clear all
set matsize 11000
set maxvar 11000

cap ssc install reghdfe
cap ssc install eststo
cap ssc install distinct

cap ssc install did_multiplegt_stat
cap ssc install eventstudyinteract
cap ssc install csdid
cap ssc install did_imputation

********************************************************************************
*                    TABLE A5: EFFECT OF CEO'S TRUST ON R&D                    *
********************************************************************************
cap log close
log using "Table A5_Effect on R&D.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"


//PREPARE TABLE
eststo clear
eststo col1: /// R&D expenditure
	reghdfe ash_xrd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "0-year"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// R&D expenditure, 1-year forward
	reghdfe ash_f1xrd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "1-year"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// R&D expenditure, 2-year forward
	reghdfe ash_f2xrd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "2-year"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// R&D stock
	reghdfe ash_rdstock trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "0-year"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// R&D stock, 1-year forward
	reghdfe ash_f1rdstock trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "1-year"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// R&D stock, 2-year forward
	reghdfe ash_f2rdstock trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "2-year"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))

esttab /*using "Table A5_Effect on R&D.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(18) modelwidth(12) ///
	mgroups("arsinh(R\&D expenditure)" "arsinh(R\&D stock)", pattern(1 0 0 1 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd) coeflab(trust_sd "CEO's trust") ///
	stats(forward FE controls N nofirms, fmt(%9.2fc %9.0fc %9.0fc) ///
		lab("Forward" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

cap log close

********************************************************************************
*     TABLE A6: ROBUSTNESS CHECKS FOR CEO'S TRUST EFFECT ON FIRM'S PATENTS     *
********************************************************************************
cap log close
log using "Table A6_Robustness checks.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"
* set sample
qui reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) keepsin
gen sample = e(sample)


//PREPARE TABLE
* PANEL A: Alternative control variables and Poisson model
eststo clear
eststo col1: /// no controls
	reghdfe ash_f1allpat trust_sd if sample, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local spec       "No ctrls"
		estadd local FE         "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// baseline
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local spec       "Baseline"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// logat control
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} logat if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local spec       "Add ctrls"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// logsale control
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} logsale if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local spec       "Add ctrls"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// logemp control
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} logemp if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local spec       "Add ctrls"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// asinh(rdstock) control
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ash_rdstock if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local spec       "Add ctrls"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
eststo col7: /// asinh(xrd) control
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ash_xrd if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local spec       "Add ctrls"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
xtset boardid
eststo col8: /// poisson
	xtpoisson f1allpat trust_sd ${firm} ${ceo} i.year if ${sample}, fe vce(robust) 
		sum f1allpat if e(sample)
		estadd scalar depvarmean = r(mean)
		estadd local spec       "Poisson"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))

global coeflist = "trust_sd logat logsale logemp ash_rdstock ash_xrd"
esttab /*using "Table A6_Robustness checks_Panel A.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(18) modelwidth(12) ///
	mgroups("Future patent applications", pattern(1 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist}) order(${coeflist}) ///
	coeflab(trust_sd "CEO's trust" ///
			logat "log(total assets)" ///
			logsale "log(sales)" ///
			logemp "log(employment)" ///
			ash_rdstock "arsinh(R\&D stock)" ///
			ash_xrd "arsinh(R\&D exp.)") ///
	stats(spec FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Specification" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


* PANEL B: Alternative clustering schemes, weighting schemes, and patent transformations
eststo clear
cap drop TRUST
gen TRUST = trust_sd 
set seed 7
eststo col1: /// Wild bootstrap
	 wildbootstrap areg ash_f1allpat TRUST ${firm} ${ceo} i.year if ${sample}, ///
		absorb(boardid) cluster(${cluster}) coefficients(TRUST)
		sum ash_f1allpat if e(sample)
		estadd local cluster    "Wild"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// cluster by CEO
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(ceoid) keepsin 
		sum ash_f1allpat if e(sample)
		estadd local cluster    "CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// two-way clustering	
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(mainethcode boardid) keepsin 
		sum ash_f1allpat if e(sample)
		estadd local cluster    "Two-way"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// aw = ethHHI
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample} [aw = ethHHI], ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local weight     "Mapping precsion"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
replace TRUST = trustmaineth_sd
eststo col5: /// trustmaineth_sd as X variable
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample} [aw = mainethshare], ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local weight     "Main ethnicity"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
replace TRUST = trust_sd
gen log1_f1allpat = log(1 + f1allpat)
eststo col6: /// log1_f1allpat as Y variable
	reghdfe log1_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local transform  "ln(1+.)"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
eststo col7: /// f1allpatw as Y variable
	reghdfe f1allpatw TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpatw if e(sample)
		estadd scalar depvarmean = r(mean)
		estadd local transform  "win"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
eststo col8: /// f1allpat as Y var
	reghdfe f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpat if e(sample)
		estadd scalar depvarmean = r(mean)
		estadd local transform  "none"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))

esttab /*using "Table A6_Robustness checks_Panel B.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(18) modelwidth(12) ///
	mgroups("Future patent applications", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(TRUST) order(TRUST) coeflab(TRUST "CEO's trust") ///
	stats(depvarmean cluster weight transform FE controls N nofirms, fmt(%9.3fc %9.0fc) ///
		lab("Dep. var. mean" "Clustering scheme" "Weighting scheme" "Transformation" ///
			"Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


* PANEL C: Alternative patent and trust measures
eststo clear
cap drop TRUST
gen TRUST = trust_sd
eststo col1: /// granted USPTO patents
	reghdfe ash_f1uspat_granted TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local patent     "Granted USPTO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
replace TRUST = trustlasso_sd
eststo col2: /// LASSO-based trust
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local trust      "LASSO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
replace TRUST = trustfullgss_sd
eststo col3: /// full-GSS-based trust
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local trust      "Full GSS"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
replace TRUST = trustwvs_sd
eststo col4: /// WVS-based trust
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local trust      "WVS"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
replace TRUST = trustgps_sd
eststo col5: /// GPS-based trust
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local trust      "GPS"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
replace TRUST = fair_sd
eststo col6: /// fairness question
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local trust      "Fairness"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
replace TRUST = helpful_sd
eststo col7: /// helpful intention question
	reghdfe ash_f1allpat TRUST ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local trust      "Helpful"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))

esttab /*using "Table A6_Robustness checks_Panel C.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(18) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(TRUST) order(TRUST) coeflab(TRUST "CEO's trust") ///
	stats(patent trust FE controls N nofirms, fmt(%9.3fc %9.0fc %9.0fc) ///
		lab("Patent measure" "Trust measure" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


* PANEL D: Alternative sample restrictions
eststo clear
eststo col1: /// excluding singletons
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster})
		estadd local transform  "arsinh(.)"
		estadd local sampexcl   "Singletons"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// excluding female CEOs
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& gender != 2, a(boardid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local sampexcl   "Female CEOs"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// excluding interim CEOs
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& !interimCEO, a(boardid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local sampexcl   "Interim CEOs"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// 2000-2014
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if year < 2015 & !nonUS, ///
		a(boardid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local sampper    "2000-14"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// only patenting firms
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& haspat, a(boardid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local sampincl   "Patent firms"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// only during patenting period
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& haspat & inrange(year, firstpatyear-1, lastpatyear), ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local transform  "arsinh(.)"
		estadd local sampincl   "Patent period"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
eststo col7: /// only patenting years
	reghdfe log_f1allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin 
		estadd local transform  "ln(.)"
		estadd local sampincl   "Patent years"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
gen D_f1allpat = f1allpat > 0
eststo col8: /// D_f1allpat as Y var
	reghdfe D_f1allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum D_f1allpat if e(sample)
		estadd scalar depvarmean = r(mean)
		estadd local transform  "1(.>0)"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))

esttab /*using "Table A6_Robustness checks_Panel D.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(18) modelwidth(12) ///
	mgroups("Future patent applications", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd) coeflab(trust_sd "CEO's trust") ///
	stats(depvarmean transform sampexcl sampper sampincl FE controls N nofirms, fmt(%9.3fc %9.0fc %9.0fc) ///
		lab("Dep. var. mean" "Transformation" "Sample excluding" "Sample period" "Sample including" ///
			"Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


* PANEL E: Alternative time lags before patent filing	
eststo clear
eststo col1: ///
	reghdfe ash_allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum ash_f1allpat if e(sample)
		estadd local forward    "0-year"
		estadd local sample     "Year T"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// 
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& year <= termendyr-1, a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "1-year"
		estadd local sample     "T - 1"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: ///
	reghdfe ash_f2allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "2-year"
		estadd local sample     "T"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: ///
	reghdfe ash_f2allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& year <= termendyr-1, a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "2-year"
		estadd local sample     "T-1"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: ///
	reghdfe ash_f2allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& year <= termendyr-2, a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "2-year"
		estadd local sample     "T-2"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: ///
	reghdfe ash_f3allpat trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "3-year"
		estadd local sample     "T"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
eststo col7: ///
	reghdfe ash_f3allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& year <= termendyr-1, a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "3-year"
		estadd local sample     "T-1"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
eststo col8: ///
	reghdfe ash_f3allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& year <= termendyr-2, a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "3-year"
		estadd local sample     "T-2"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))
eststo col9: ///
	reghdfe ash_f3allpat trust_sd ${firm} ${ceo} if ${sample} ///
	& year <= termendyr-3, a(boardid year) cluster(${cluster}) keepsin
		estadd local forward    "3-year"
		estadd local sample     "T-3"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col9, add(nofirms r(ndistinct))

esttab /*using "Table A6_Robustness checks_Panel E.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(18) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd) coeflab(trust_sd "CEO's trust") ///
	stats(forward sample FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Forward" "Sample including" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

	
* PANEL F: Alternative CEO transition event sample
use "CEO transition event sample.dta", clear
*** construct additional variables
replace moretrust = 9 if moretrust + lesstrust == 0
gen D_f1allpat = f1allpat > 0
gen postxdeltatrust = postchange * deltatrust if trust_sd != .
gen postxtrustbf = postchange * trustbf if trust_sd != .
*** set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global eventsample = "!bothnonUS"
global cluster = "mainethcode"

eststo clear
eststo col1: /// baseline
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col1, add(noevents r(ndistinct))
eststo col2: /// by change in trust
	reghdfe ash_f1allpat c.trust_sd##c.deltatrust ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col2, add(noevents r(ndistinct))
eststo col3: /// by trust-decreasing vs. trust-increasing
	reghdfe ash_f1allpat c.trust_sd#i.moretrust ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col3, add(noevents r(ndistinct))
eststo col4: /// non-patenting pre-transition
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
	& haspatpre == 0, a(eventid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local haspatpre  "No"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col4, add(noevents r(ndistinct))
eststo col5: /// patenting pre-transition
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
	& haspatpre == 1, a(eventid year) cluster(${cluster}) keepsin
		estadd local transform  "arsinh(.)"
		estadd local haspatpre  "Yes"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col5, add(noevents r(ndistinct))
eststo col6: /// extensive margin among patenting pre-transition
	reghdfe D_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
	& haspatpre == 1, a(eventid year) cluster(${cluster}) keepsin
		sum D_f1allpat if e(sample)
		estadd scalar depvarmean = r(mean)
		estadd local transform  "1(.>0)"
		estadd local haspatpre  "Yes"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col6, add(noevents r(ndistinct))
eststo col7: /// preceding CEO's trust as IV for change in trust, RF
	reghdfe ash_f1allpat postxtrustbf postchange ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(mainethcoder) keepsin
		estadd local transform  "arsinh(.)"
		estadd local spec       "RF"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col7, add(noevents r(ndistinct))
eststo col8: /// preceding CEO's trust as IV for change in trust, IV
	ivreghdfe ash_f1allpat (postxdeltatrust = postxtrustbf) postchange ${firm} ${ceo} ///
	if ${eventsample}, a(eventid year) cluster(mainethcoder) keepsin first
		estadd local transform  "arsinh(.)"
		estadd local spec       "IV"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col8, add(noevents r(ndistinct))

global coeflist1 = "trust_sd c.trust_sd#c.deltatrust 0.moretrust#c.trust_sd 1.moretrust#c.trust_sd"
global coeflist2 = "postxtrustbf postxdeltatrust"
esttab /*using "Table A6_Robustness checks_Panel F.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(35) modelwidth(12) ///
	mgroups("Future patent applications", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist1} ${coeflist2}) order(${coeflist1} ${coeflist2}) ///
	coeflab(trust_sd "CEO's trust" ///
			c.trust_sd#c.deltatrust "Trust $\times$ Change in trust" ///
			0.moretrust#c.trust_sd "Trust $\times$ 1(Trust-decreasing)" ///
			1.moretrust#c.trust_sd "Trust $\times$ 1(Trust-increasing)" ///
			postxtrustbf "Post $\times$ Preceding CEO's trust" ///
			postxdeltatrust "Post $\times$ Change in trust") ///
	stats(depvarmean transform spec haspatpre FE controls N noevents, fmt(%9.3fc %9.0fc %9.0fc) ///
		lab("Dep. var. mean" "Tranformation" "Specificaiton" "Patenting pre-transition" ///
			"Event \& Year FEs" "Baseline controls" "Observations" "Events"))


* PANEL G: Alternative difference-in-differences specifications
use "CEO transition event sample.dta", clear
keep if !bothnonUS & trust_sd != .
*** construct additional variables
gen tempyear = year if postchange == 1
bysort eventid: egen cohort = min(tempyear)
drop tempyear
*** clean multiple eventid x year observations 
bysort eventid year: gen count = _N
drop if count > 1 & postchange == 0
drop count
bysort eventid year: gen count = _N
drop if count > 1
drop count
bysort eventid: egen min = min(postchange)
bysort eventid: egen max = max(postchange)
drop if min == max
drop min max
*** set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global eventsample = "moretrust == 1 | lesstrust == 1"
global cluster = "eventid"
keep if ${eventsample}

*** DE CHAISEMARTIN & D'HAULTFOEUILLE
cap drop educ_*
forval i = 1/4 {
	gen educ_`i' = education == `i'
	replace educ_`i' = . if education == .
}
* Col (1):
did_multiplegt_stat ash_f1allpat eventid year trust_sd, ///
	controls(firmage* gender age* yrinco educ_*) cluster(${cluster})

*** TWO-WAY FIXED EFFECTS
* Col (2):
reghdfe ash_f1allpat c.moretrust##c.postchange ${firm} ${ceo}, ///
	a(eventid year) cluster(${cluster})

*** SUN & ABRAHAM
cap drop year_*
forval i = 0/14 {
	gen year_`i' = year == `i'	
}
drop year_6
cap drop not*
gen notmoretrust = !moretrust	
gen notlesstrust = !lesstrust	
* Col (3):
eventstudyinteract ash_f1allpat postchange, cohort(cohort) control_cohort(notmoretrust) ///
	covariates(${firm} ${ceo} postchange) absorb(eventid year) vce(cluster ${cluster})
* Col (4):	
eventstudyinteract ash_f1allpat postchange, cohort(cohort) control_cohort(notlesstrust) ///
	covariates(${firm} ${ceo} postchange) absorb(eventid year) vce(cluster ${cluster})

*** CALLAWAY & SANT'ANNA
cap drop cohort_*
gen cohort_more = cohort
replace cohort_more = 0 if !moretrust
gen cohort_less = cohort
replace cohort_less = 0 if !lesstrust
* Col (5):
csdid ash_f1allpat ${firm} ${ceo} postchange, ivar(eventid) time(year) gvar(cohort_more) agg(simple)
* Col (6):
csdid ash_f1allpat ${firm} ${ceo} postchange, ivar(eventid) time(year) gvar(cohort_less) agg(simple)

*** BORUSYAK ET AL.
cap drop cohort_*
gen cohort_more = cohort
replace cohort_more = . if !moretrust
gen cohort_less = cohort
replace cohort_less = . if !lesstrust
* Col (7): 
did_imputation ash_f1allpat eventid year cohort_more, ///
	controls(postchange firmage* gender age* yrinco educ_*) cluster(${cluster}) autosample tol(0.001)
* Col (8):
did_imputation ash_f1allpat eventid year cohort_less, ///
	controls(postchange firmage* gender age* yrinco educ_*) cluster(${cluster}) autosample tol(0.001)

cap log close
	
********************************************************************************
*                 TABLE A7: CEO'S RETIREMENT AND DEATH EVENTS                  *
********************************************************************************
cap log close
log using "Table A7_Retirement and death events.log", replace

//PREPARE DATA
use "CEO transition event sample.dta", clear
* construct additional variables
gen postxdeltatrust = postchange * deltatrust if trust_sd != .
gen postxtrustbf = postchange * trustbf  if trust_sd != .
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global eventsample = "!bothnonUS"
global cluster = "mainethcode"


//PREPARE TABLE
foreach panel in "A" "B" {
	* PANEL A: Including all years in each event
	* PANEL B: Excluding transition years
	if "`panel'" == "B" {
		preserve
		bysort eventid: egen tempendyr = max(termendyr) if postchange == 0
		bysort eventid: egen starttermendyr = mean(tempendyr)
		drop if year == starttermendyr & postchange == 1
	}
	
	eststo clear
	eststo col1: /// retired at 65
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
		& retire1yr, a(eventid year) cluster(${cluster}) keepsin
			estadd local sample     "Retd 65"
			estadd local spec       "OLS"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col1, add(noevents r(ndistinct))
	eststo col2: /// retired between 64-66
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
		& retire3yr, a(eventid year) cluster(${cluster}) keepsin
			estadd local sample     "Retd 64-66"
			estadd local spec       "OLS"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col2, add(noevents r(ndistinct))
	eststo col3: /// retired between 63-67
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
		& retire5yr, a(eventid year) cluster(${cluster}) keepsin
			estadd local sample     "Retd 63-67"
			estadd local spec       "OLS"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col3, add(noevents r(ndistinct))
	eststo col4: /// died within transition year
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
		& deathwi0yr, a(eventid year) cluster(${cluster}) keepsin
			estadd local sample     "Died trans yr"
			estadd local spec       "OLS"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col4, add(noevents r(ndistinct))
	eststo col5: /// died within transition year + 1
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
		& deathwi1yr, a(eventid year) cluster(${cluster}) keepsin
			estadd local sample     "Died trans yr+1"
			estadd local spec       "OLS"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col5, add(noevents r(ndistinct))
	eststo col6: /// retired or died OLS
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
		& (retire5yr | deathwi1yr), a(eventid year) cluster(${cluster}) keepsin
			estadd local sample     "Retd/died"
			estadd local spec       "OLS"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col6, add(noevents r(ndistinct))
	eststo col7: /// retired or died RF
		reghdfe ash_f1allpat postxtrustbf postchange ${firm} ${ceo} if ${eventsample} ///
		& (retire5yr | deathwi1yr), a(eventid year) cluster(mainethcoder) keepsin
			estadd local sample     "Retd/died"
			estadd local spec       "RF"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col7, add(noevents r(ndistinct))
	eststo col8: /// retired or died IV
		ivreghdfe ash_f1allpat (postxdeltatrust = postxtrustbf) postchange ${firm} ${ceo} if ${eventsample} ///
		& (retire5yr | deathwi1yr), a(eventid year) cluster(mainethcoder) keepsin first
			estadd local sample 	"Retd/died"
			estadd local spec       "IV"
			estadd local FE         "X"
			estadd local controls   "X"
			distinct eventid if e(sample)
			eststo col8, add(noevents r(ndistinct))
	cap restore		
	
	global coeflist = "trust_sd postxtrustbf postxdeltatrust"
	esttab /*using "Table A7_Retirement and death events_Panel `panel'.tex"*/, ///
		cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
		nomtitle collabels(none) label varwidth(35) modelwidth(13) ///
		mgroups("arsinh(Future patent applications)" "\textbf{D(.)}", pattern(1 0 0 0 0 0 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		keep(${coeflist}) order(${coeflist}) ///
		coeflab(trust_sd "CEO's trust" ///
				trustbf "Predecessor CEO's trust" ///
				postxtrustbf "Post $\times$ Preceding CEO's trust" ///
				postxdeltatrust	"Post $\times$ Change in trust") ///
		stats(sample spec FE controls N noevents, fmt(%9.0fc %9.0fc) ///
			lab("Sample" "Specification" "Event \& Year FEs" "Baseline controls" "Observations" "Events"))
}

cap log close

********************************************************************************
*        TABLE A8: CONTROLLING FOR CEO'S HOME COUNTRY'S CHARACTERISTICS        *
********************************************************************************
cap log close
log using "Table A8_Home country characteristics.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global country = "logGDP logpop GDPgr lsc gov3_pcr logustradevol logcallpat"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"


//PREPARE TABLE
eststo clear
eststo col1: /// GDP, population, GDP growth
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} logGDP logpop GDPgr ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// high school graduate share
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} lsc ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// governance quality
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} gov3_pcr ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// US trade volume
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} logustradevol ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// country patent applications
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} logcallpat ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// all home country controls
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ${country} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
		
esttab /*using "Table A8_Home country characteristics.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(31) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd ${country}) order(trust_sd ${country}) ///
	coeflab(trust_sd "CEO's trust" ///
			logGDP "ln(GDP)" ///
			logpop "ln(Population)" ///
			GDPgr "GDP growth (\%)" ///
			lsc "High school grads (share)" ///
			gov3_pcr "Governance quality (percentile)" ///
			llgdp "Liabilites/GDP" ///
			logustradevol "ln(US trade volume)" ///
			logcallpat "ln(Patent applications)") ///
	stats(FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

cap log close

********************************************************************************
*               TABLE A9: CONTROLLING FOR OTHER CULTURAL TRAITS                *
********************************************************************************
cap log close
log using "Table A9_Other cultural traits.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global culture = "highincome_sd getahead_sd risktakinggps_sd patiencegps_sd"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"


//PREPARE TABLE
* PANEL A: Main results
eststo clear
eststo col1: /// high-income share
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} highincome_sd ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// work ethic
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} getahead_sd ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// risk preference
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} risktakinggps_sd ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// patience
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} patiencegps_sd ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// all cultural trait controls
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ${culture} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// all cultural trait controls & GDP growth
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ${culture} GDPgr ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))

esttab /*using "Table A9_Other cultural traits_Panel A.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(27) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd ${culture} GDPgr) order(trust_sd ${culture} GDPgr) ///
	coeflab(trust_sd "CEO's trust" ///
			highincome_sd "High-income share (z-score)" ///
			getahead_sd "Work ethic (z-score)" ///
			risktakinggps_sd "Risk preference (z-score)" ///
			patiencegps_sd "Patience (z-score)" ///
			GDPgr "GDP growth (\%)" ///
			logustradevol "ln(US trade volume)") ///
	stats(FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


* PANEL B: Other measures of other cultural traits
eststo clear
eststo col1: /// occupation prestige
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} prestg_sd ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// average school years
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} educyrs ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// college graduate share
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} coldeg ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// Protestant share
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} protestant ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// confidence in science
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} consci_sd ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// confidence in Congress, Federal Government, Supreme Court
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} conleg_sd confed_sd conjud_sd ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
		
global coeflist = "trust_sd prestg_sd educyrs coldeg protestant consci_sd conleg_sd confed_sd conjud_sd"
esttab /*using "Table A9_Other cultural traits_Panel B.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(37) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist}) order(${coeflist}) ///
	coeflab(trust_sd "CEO's trust (baseline)" ///
			prestg_sd "Occupation prestige (z-score)" ///
			educyrs "Average schooling years" ///
			coldeg "College graduates (share)" ///
			protestant "Protestants (share)" ///
			consci_sd "Confidence in science (z-score)" ///
			conleg_sd "Confidence in Congress (z-score)" ///
			confed_sd "Confidence in Federal Govt. (z-score)" ///
			conjud_sd "Confidence in Supreme Court (z-score)") ///
	stats(FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

cap log close

********************************************************************************
*    TABLE A10: GLOBAL PREFERENCE SURVEY'S TRUST AND OTHER CULTURAL TRAITS     *
********************************************************************************
cap log close
log using "Table A10_GPS other cultural traits.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global gpsvars = "risktakinggps_sd patiencegps_sd posrecipgps_sd negrecipgps_sd altruismgps_sd"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"

//PREPARE TABLE
foreach panel in "A" "B" {
	* PANEL A: Using GPS-based CEO's inherited trust measure
	if "`panel'" == "A" {
		cap drop TRUST
		gen TRUST = trustgps_sd
		global source = "GPS"
	}
	* PANEL B: Using baseline GSS-based CEO's inherited trust measure
	if "`panel'" == "B" {
		cap drop TRUST
		gen TRUST = trust_sd
		global source = "GSS"
	}
	
	eststo clear
	eststo col1: /// no controls
		reghdfe ash_f1allpat TRUST ${firm} ${ceo} ///
		if ${sample}, a(boardid year) cluster(${cluster}) keepsin
			estadd local FE         "X"
			estadd local controls   "X"
			distinct boardid if e(sample)
			eststo col1, add(nofirms r(ndistinct))
	eststo col2: /// risk prefence
		reghdfe ash_f1allpat TRUST ${firm} ${ceo} risktakinggps_sd ///
		if ${sample}, a(boardid year) cluster(${cluster}) keepsin
			estadd local FE         "X"
			estadd local controls   "X"
			distinct boardid if e(sample)
			eststo col2, add(nofirms r(ndistinct))
	eststo col3: /// patience
		reghdfe ash_f1allpat TRUST ${firm} ${ceo} patiencegps_sd ///
		if ${sample}, a(boardid year) cluster(${cluster}) keepsin
			estadd local FE         "X"
			estadd local controls   "X"
			distinct boardid if e(sample)
			eststo col3, add(nofirms r(ndistinct))
	eststo col4: /// positive reciprocity
		reghdfe ash_f1allpat TRUST ${firm} ${ceo} posrecipgps_sd ///
		if ${sample}, a(boardid year) cluster(${cluster}) keepsin
			estadd local FE         "X"
			estadd local controls   "X"
			distinct boardid if e(sample)
			eststo col4, add(nofirms r(ndistinct))
	eststo col5: /// negative reciprocity
		reghdfe ash_f1allpat TRUST ${firm} ${ceo} negrecipgps_sd ///
		if ${sample}, a(boardid year) cluster(${cluster}) keepsin
			estadd local FE         "X"
			estadd local controls   "X"
			distinct boardid if e(sample)
			eststo col5, add(nofirms r(ndistinct))
	eststo col6: /// altruism
		reghdfe ash_f1allpat TRUST ${firm} ${ceo} altruismgps_sd ///
		if ${sample}, a(boardid year) cluster(${cluster}) keepsin
			estadd local FE         "X"
			estadd local controls   "X"
			distinct boardid if e(sample)
			eststo col6, add(nofirms r(ndistinct))
	eststo col7: /// all GPS cultural trait controls	
		reghdfe ash_f1allpat TRUST ${firm} ${ceo} ${gpsvars} ///
		if ${sample}, a(boardid year) cluster(${cluster}) keepsin
			estadd local FE         "X"
			estadd local controls   "X"
			distinct boardid if e(sample)
			eststo col7, add(nofirms r(ndistinct))
	
	esttab /*using "Table A10_GPS other cultural traits_Panel `panel'.tex"*/, ///
		cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
		nomtitle collabels(none) label varwidth(20) modelwidth(12) ///
		mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		keep(TRUST ${gpsvars}, relax) order(TRUST ${gpsvars}, relax) ///
		coeflab(TRUST "CEO's trust (${source})" ///
				risktakinggps_sd "Risk preference" ///
				patiencegps_sd "Patience" ///
				posrecipgps_sd "Positive reciprocity" ///
				negrecipgps_sd "Negative reciprocity" ///
				altruismgps_sd  "Altruism") ///
		stats(FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
			lab("Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))
}

cap log close

********************************************************************************
*        TABLE A11: CEO'S TRUST EFFECT ACROSS INDUSTRIES AND FIRM SIZES        *
********************************************************************************
cap log close
log using "Table A11_Effect across industries and sizes.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* construct additional variables
gen pharmachem = inlist(sector, ///
	"Chemicals", ///
	"Pharmaceuticals and Biotechnology", ///
	"Health")
gen electroit = inlist(sector, ///
	"Electronic & Electrical Equipment", ///
	"Information Technology Hardware", ///
	"Software & Computer Services")
gen timesinceCEO = min(year - termstartyr, 9)
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"


//PREPARE TABLE
eststo clear
eststo col1: /// pharma/chemical industries
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ///
	if ${sample} & pharmachem, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Pharma/chem"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// pharma/chemical industries, by tenure as CEO
	reghdfe ash_f1allpat c.trust_sd##c.timesinceCEO ${firm} ${ceo} ///
	if ${sample} & pharmachem, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Pharma/chem"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// ICT/electronic industries
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ///
	if ${sample} & electroit, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "ICT/elec"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// ICT/electronic industries, by tenure as CEO
	reghdfe ash_f1allpat c.trust_sd##c.timesinceCEO ${firm} ${ceo} ///
	if ${sample} & electroit, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "ICT/elec"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// other industries
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ///
	if ${sample} & !(pharmachem | electroit), a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Others"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
gen sizepct = sizepct_at_sic3
eststo col6: /// by asset size quintile
	reghdfe ash_f1allpat c.trust_sd#i.sizepct i.sizepct ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Full"
		estadd local sizepct    "By asset"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
replace sizepct = sizepct_emp_sic3
eststo col7: /// by employment size quintile
	reghdfe ash_f1allpat c.trust_sd#i.sizepct i.sizepct ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Full"
		estadd local sizepct    "By emp"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
replace sizepct = sizepct_at_sic3haspat
eststo col8: /// by asset size quintile during patent period
	reghdfe ash_f1allpat c.trust_sd#i.sizepct i.sizepct ${firm} ${ceo} ///
	if ${sample} & haspat & inrange(year, firstpatyear-1, lastpatyear), ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Pat period"
		estadd local sizepct    "By asset"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))
replace sizepct = sizepct_emp_sic3haspat
eststo col9: /// by employment size quintile during patent period
	reghdfe ash_f1allpat c.trust_sd#i.sizepct i.sizepct ${firm} ${ceo} ///
	if ${sample} & haspat & inrange(year, firstpatyear-1, lastpatyear), ///
	a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Pat period"
		estadd local sizepct    "By emp"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col9, add(nofirms r(ndistinct))

global coeflist1 = "trust_sd c.trust_sd#c.timesinceCEO"
global coeflist2 = "1.sizepct#c.trust_sd 2.sizepct#c.trust_sd 3.sizepct#c.trust_sd 4.sizepct#c.trust_sd 5.sizepct#c.trust_sd"
esttab /*using "Table A11_Effect across industries and sizes.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(30) modelwidth(11) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist1} ${coeflist2}) order(${coeflist1} ${coeflist2}) ///
	coeflab(trust_sd "CEO's trust" ///
			c.trust_sd#c.timesinceCEO "Trust $\times$ Tenure as CEO" ///
			1.sizepct#c.trust_sd "Trust $\times$ Size quintile 1" ///
			2.sizepct#c.trust_sd "Trust $\times$ Size quintile 2" ///
			3.sizepct#c.trust_sd "Trust $\times$ Size quintile 3" ///
			4.sizepct#c.trust_sd "Trust $\times$ Size quintile 4" ///
			5.sizepct#c.trust_sd "Trust $\times$ Size quintile 5") ///
	stats(sample sizepct FE controls N nofirms, fmt( %9.3fc %9.3fc %9.0fc %9.0fc) ///
		lab("Sample" "Firm size quintile" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

cap log close

********************************************************************************
*       TABLE A12: CEO'S TRUST EFFECT BY CEO'S BACKGROUND AND EXPERIENCE       *
********************************************************************************
cap log close
log using "Table A12_Effect by background and experience.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* construct additional variables
gen postgradnonMBA = (education == 3 & MBA == 0) | education == 4
gen postgrad = education == 3 | education == 4
gen hasPhD = education == 4
foreach var of varlist postgrad postgradnonMBA postgrad hasPhD {
	replace `var' = . if education == .
}
gen hasRDexp = preCEO_resdir == 1 | preCEO_techdir == 1
gen above3yrinco = yrinco > 3
* set globals
global firm = "firmage firmage2"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"

//PREPARE TABLE
eststo clear
global ceo = "gender age age2 yrinco"
cap drop D
gen D = postgrad
eststo col1: /// graduate degree
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Graduate"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))	
replace D = hasPhD
eststo col2: /// doctorate degree
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Doctorate"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
replace D = postgradnonMBA
eststo col3: /// non-MBA graduate degree
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Non-MBA grad"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
global ceo = "gender age age2 yrinco i.education"
replace D = hasRDexp
eststo col4: /// prior R&D experience
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "R\&D exp"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
global ceo = "gender age age2 i.education"
replace D = above3yrinco
eststo col5: /// more than 3 years in firm
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       ">3 yrs in firm"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
global ceo = "gender age age2 yrinco i.education"
replace D = firstgen | nonUSUKedu
eststo col6: /// born or educated abroad
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Born/edu abroad"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
replace D = firstgen
eststo col7: /// born abroad
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Born abroad"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
replace D = sameethnames
eststo col8: /// same-ethnicity first name
	reghdfe ash_f1allpat c.trust_sd#i.D D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Same-eth names"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))
		
esttab /*using "Table A12_Effect by background and experience.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(23) modelwidth(13) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(0.D#c.trust_sd 1.D#c.trust_sd) order(0.D#c.trust_sd 1.D#c.trust_sd) ///
	coeflab(0.D#c.trust_sd "A: Trust $\times$ D = 0" ///
			1.D#c.trust_sd "B: Trust $\times$ D = 1") ///
	stats(Dvar FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("CEO's background" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


//PRINT DIFFERENCES
eststo clear
global ceo = "gender age age2 yrinco"
cap drop D
gen D = postgrad
eststo col1: /// graduate degree
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Graduate"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
replace D = hasPhD
eststo col2: /// doctorate degree
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Doctorate"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
replace D = postgradnonMBA
eststo col3: /// non-MBA graduate degree
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Non-MBA grad"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
global ceo = "gender age age2 yrinco i.education"
replace D = hasRDexp
eststo col4: /// prior R&D experience
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "R\&D exp"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
global ceo = "gender age age2 i.education"
replace D = above3yrinco
eststo col5: /// more than 3 years in firm
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       ">3 yrs in firm"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
global ceo = "gender age age2 yrinco i.education"
replace D = firstgen | nonUSUKedu
eststo col6: /// born or educated abroad
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Born/edu abroad"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
replace D = firstgen
eststo col7: /// born abroad
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Born abroad"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
replace D = sameethnames
eststo col8: /// same-ethnicity first name
	reghdfe ash_f1allpat c.trust_sd##c.D ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local Dvar       "Same-eth names"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))

esttab /*using "Table A12_Effect by background and experience_Difference.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(23) modelwidth(13) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(c.trust_sd#c.D) order(c.trust_sd#c.D) coeflab(c.trust_sd#c.D "Difference: B - A") ///
	stats(Dvar FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		labels("CEO's background" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

cap log close

********************************************************************************
*           TABLE A13: CEO'S TRUST EFFECT BY GENDER AND GENDER NORMS           *
********************************************************************************
cap log close
log using "Table A13_Effect by gender and gender norms.log", replace
	
//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"


//PREPARE TABLE
* PANEL A: CEO's trust effect by CEO's gender and gender norms
eststo clear
eststo col1: /// by CEO's gender
	reghdfe ash_f1allpat c.trust_sd##i.gender ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local qualweight "None"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, addscalars(nofirms r(ndistinct))
eststo col2: /// CEO's gender norms control
	reghdfe ash_f1allpat trust_sd LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin	
		estadd local qualweight "None"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, addscalars(nofirms r(ndistinct))
eststo col3: /// by CEO's gender norms
	reghdfe ash_f1allpat c.trust_sd##c.LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin	
		estadd local qualweight "None"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, addscalars(nofirms r(ndistinct))
eststo col4: /// citation-weighted, by CEO's gender
	reghdfe ash_f1allpat_citff c.trust_sd##i.gender ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local qualweight "Fwd cites"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, addscalars(nofirms r(ndistinct))
eststo col5: /// citation-weighted, CEO's gender norms control
	reghdfe ash_f1allpat_citff trust_sd LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin	
		estadd local qualweight "Fwd cites"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, addscalars(nofirms r(ndistinct))
eststo col6: /// citation-weighted, by CEO's gender norms 
	reghdfe ash_f1allpat_citff c.trust_sd##c.LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin	
		estadd local qualweight "Fwd cites"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, addscalars(nofirms r(ndistinct))

global coeflist = "trust_sd 2.gender#c.trust_sd LFPR_sd_c c.trust_sd#c.LFPR_sd_c"
esttab /*using "Table A13_Effect by gender and gender norms_Panel A.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(28) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist}) order(${coeflist}) ///
	coeflab(trust_sd "CEO's trust" ///
			2.gender#c.trust_sd "Trust $\times$ Female CEO" ///
			LFPR_sd_c "F/M LFP ratio (z-score)" ///
			c.trust_sd#c.LFPR_sd_c "Trust $\times$ F/M LFP ratio") ///
	stats(qualweight FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Quality weight" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


* PANEL B: CEO's trust effect by inventors' gender and CEO's gender norms
eststo clear
eststo col1: /// patents by female inventors
	reghdfe ash_f1allpat_f trust_sd ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		cap drop sample
		gen sample = e(sample)
		estadd local qualweight "None"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, addscalars(nofirms r(ndistinct))
eststo col2: /// patents by male inventors
	reghdfe ash_f1allpat_m trust_sd ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local qualweight "None"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, addscalars(nofirms r(ndistinct))
eststo col3: /// patents by female inventors, by CEO's gender norms
	reghdfe ash_f1allpat_f c.trust_sd##c.LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin	
		estadd local qualweight "None"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, addscalars(nofirms r(ndistinct))
eststo col4: /// patents by male inventors, by CEO's gender norms
	reghdfe ash_f1allpat_m c.trust_sd##c.LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin			
		estadd local qualweight "None"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, addscalars(nofirms r(ndistinct))
eststo col5: /// citation-weighted patents by female inventors
	reghdfe ash_f1allpat_citff_f trust_sd ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local qualweight "Fwd cites"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, addscalars(nofirms r(ndistinct))
eststo col6: /// citation-weighted patents by male inventors
	reghdfe ash_f1allpat_citff_m trust_sd ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin
		estadd local qualweight "Fwd cites"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, addscalars(nofirms r(ndistinct))
eststo col7: /// citation-weighted patents by female inventors, by CEO's gender norms
	reghdfe ash_f1allpat_citff_f c.trust_sd##c.LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin	
		estadd local qualweight "Fwd cites"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, addscalars(nofirms r(ndistinct))
eststo col8: /// citation-weighted patents by male inventors, by CEO's gender norms
	reghdfe ash_f1allpat_citff_m c.trust_sd##c.LFPR_sd_c ${firm} ${ceo} ///
	if ${sample}, a(boardid year) cluster(${cluster}) keepsin			
		estadd local qualweight "Fwd cites"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col8, addscalars(nofirms r(ndistinct))

global coeflist = "trust_sd LFPR_sd_c c.trust_sd#c.LFPR_sd_c"
esttab /*using "Table A13_Effect by gender and gender norms_Panel B.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(28) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist}) order(${coeflist}) ///
	coeflab(trust_sd "CEO's trust" ///
			LFPR_sd_c "F/M LFP ratio (z-score)" ///
			c.trust_sd#c.LFPR_sd_c "Trust $\times$ F/M LFP ratio") ///
	stats(qualweight FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Quality weight" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))


//PRINT DIFFERENCES
quietly {
	reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, ///
		a(boardid year) keepsin	
	replace sample = e(sample)
	forval i = 0/4 {
		gen educ`i' = education == `i'
	}
	forval i = 2000/2011 {
		gen year`i' = year == `i'
	}
	foreach var in ///
		ash_f1allpat_f ash_f1allpat_m ash_f1allpat_citff_f ash_f1allpat_citff_m trust_sd ///
		logat logsale firmage firmage2 gender age age2 yrinco educ1 educ2 educ3 educ4 {
		bysort boardid: egen M_`var' = mean(`var') if sample
		gen m_`var' = `var' - M_`var'
	}	
	forval i = 2000/2011 {
		bysort boardid: egen M_year`i' = mean(year`i') if sample
		gen m_year`i' = year`i' - M_year`i'
	}
	drop M_*	
}

quietly {
	reg m_ash_f1allpat_f m_trust_sd m_firmage* m_gender m_age* m_yrinco m_educ* m_year* if sample
	estimates store Female
	qui reg m_ash_f1allpat_m m_trust_sd m_firmage* m_gender m_age* m_yrinco m_educ* m_year* if sample
	estimates store Male
	suest Female Male, cluster(${cluster})
}
test [Female_mean]m_trust_sd = [Male_mean]m_trust_sd

quietly {
	reg m_ash_f1allpat_citff_f m_trust_sd m_firmage* m_gender m_age* m_yrinco m_educ* m_year* if sample
	estimates store Female
	reg m_ash_f1allpat_citff_m m_trust_sd m_firmage* m_gender m_age* m_yrinco m_educ* m_year* if sample
	estimates store Male
	suest Female Male, cluster(${cluster})
}
test [Female_mean]m_trust_sd = [Male_mean]m_trust_sd

cap log close

********************************************************************************
*               TABLE A14: CEO'S TRUST EFFECT BY PATENT QUALITY                *
********************************************************************************
cap log close
log using "Table A14_Effect by patent quality.log", replace

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"
* set sample
qui reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, a(boardid year) keepsin
gen sample = e(sample)
* construct additional variables
sum f1allpatw if sample
gen f1allpatw_sd = f1allpatw/r(mean)
foreach var in q4 q10 q20 q40 q100 {
	sum f1allpat_citff_top`var' if sample
	gen f1allpat_citff_top`var'_sd = f1allpat_citff_top`var'/r(mean)
}

//PREPARE TABLE
eststo clear
eststo col1: /// all patents
	reghdfe f1allpatw_sd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpatw if e(sample)
		estadd scalar depvarmean r(mean)
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, addscalars(nofirms r(ndistinct))
eststo col2: /// top 25% patents
	reghdfe f1allpat_citff_topq4_sd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpat_citff_topq4 if e(sample)
		estadd scalar depvarmean r(mean)
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, addscalars(nofirms r(ndistinct))
eststo col3: /// top 10% patents
	reghdfe f1allpat_citff_topq10_sd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpat_citff_topq10 if e(sample)
		estadd scalar depvarmean r(mean)
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, addscalars(nofirms r(ndistinct))
eststo col4: /// top 5% patents
	reghdfe f1allpat_citff_topq20_sd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpat_citff_topq20 if e(sample)
		estadd scalar depvarmean r(mean)
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, addscalars(nofirms r(ndistinct))
eststo col5: /// top 2.5% patents
	reghdfe f1allpat_citff_topq40_sd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpat_citff_topq40 if e(sample)
		estadd scalar depvarmean r(mean)
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, addscalars(nofirms r(ndistinct))
eststo col6: /// top 1% patents
	reghdfe f1allpat_citff_topq100_sd trust_sd ${firm} ${ceo} if ${sample}, ///
	a(boardid year) cluster(${cluster}) keepsin
		sum f1allpat_citff_topq100 if e(sample)
		estadd scalar depvarmean r(mean)
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, addscalars(nofirms r(ndistinct))

lab var f1allpatw_sd                "All patents"
lab var f1allpat_citff_topq4_sd     "Top 25\%"
lab var f1allpat_citff_topq10_sd    "Top 10\%"
lab var f1allpat_citff_topq20_sd    "Top 5\%"
lab var f1allpat_citff_topq40_sd    "Top 2.5\%"
lab var f1allpat_citff_topq100_sd   "Top 1\%"
esttab /*using "Table A14_Effect by patent quality.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	collabels(none) label varwidth(25) ///
	mgroups("Normalized future top-quality patent applications", pattern(1 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd) coeflab(trust_sd "CEO's trust") ///
	stats(depvarmean FE controls N nofirms, fmt(%9.3fc %9.3fc %9.0fc %9.0fc %9.0fc) ///
		lab("Dep. var. mean" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

cap log close

********************************************************************************
*              TABLE A15: CEO'S TRUST AND CORPORATE TRUST CULTURE              *
********************************************************************************
	
* See "Trust Innovation_Main tables figures.do"
		
********************************************************************************
*   TABLE A16: ROBUSTNESS CHECKS FOR CEO'S TRUST AND CORPORATE TRUST CULTURE   *
********************************************************************************
cap log close
log using "Table A16_Corporate trust culture robustness checks.log", replace

///PREPARE DATA
use "Employee review trust sentiment sample.dta", clear
* construct time period variables
cap drop timesinceCEO* timeperiod
gen timesinceCEO = min(year - termstartyr, 9)
gen timesinceCEO2 = timesinceCEO^2
gen timesinceCEO3 = timesinceCEO^3
gen timeperiod = 1 if inrange(timesinceCEO, 0, 2)
replace timeperiod = 2 if inrange(timesinceCEO, 3, 4)
replace timeperiod = 3 if inrange(timesinceCEO, 5, 6)
replace timeperiod = 4 if inrange(timesinceCEO, 7, 8)
replace timeperiod = 5 if timesinceCEO >= 9
* compute corporate trust culture measures
cap drop trustsentiment
gen trustsentiment = (trustsentiment_pos == 1) - (trustsentiment_neg == 1)
cap drop trust_mtoe trust_etom
gen trustsentiment_mtoe = ///
	(trustsentiment_pos == 1) * (trustdirection_mtoe == 1) ///
	- (trustsentiment_neg == 1) * (trustdirection_mtoe == 1)
gen trustsentiment_etom = ///
	(trustsentiment_pos == 1) * (trustdirection_etom == 1) ///
	- (trustsentiment_neg == 1) * (trustdirection_etom == 1) 
foreach var in trustsentiment trustsentiment_mtoe trustsentiment_etom {
	replace `var' = . if trustsentiment_pos == .
}
gen trustsentiment_mtoe_pos = (trustsentiment_pos == 1) * (trustdirection_mtoe == 1)
gen trustsentiment_mtoe_neg = (trustsentiment_neg == 1) * (trustdirection_mtoe == 1)
gen trustsentiment_etom_pos = (trustsentiment_pos == 1) * (trustdirection_etom == 1)
gen trustsentiment_etom_neg = (trustsentiment_neg == 1) * (trustdirection_etom == 1)
gen trustsentiment_abs = trustsentiment_pos | trustsentiment_neg
gen trustsentiment_mtoe_abs = trustsentiment_mtoe_pos | trustsentiment_mtoe_neg
gen trustsentiment_etom_abs = trustsentiment_etom_pos | trustsentiment_etom_neg
foreach var in trustsentiment trustsentiment_mtoe trustsentiment_etom {
	replace `var' = `var' * 100
	replace `var'_pos = `var'_pos * 100
	replace `var'_neg = `var'_neg * 100
	replace `var'_abs = `var'_abs * 100
}
* compute review counts
foreach var in trustsentiment approveceo iscurrentjob reviewgap firmage ///
	trust_sd gender age yrinco education !nonUS ///
	highincome_sd getahead_sd risktakinggps_sd patiencegps_sd {
	keep if `var' != .
}
*** all reviews
cap drop *_all
bysort boardid ceoid termstartyr: gen revcnt_all = _N
bysort boardid ceoid termstartyr: egen revcnt_allcur = sum(iscurrentjob)
gen w_all = 1/revcnt_all
gen w_allcur = 1/revcnt_allcur
*** R&D workers only
replace jobtitle = upper(jobtitle)
cap drop RDworker *_rd
gen RDworker = ///
	strpos(jobtitle, "ENGINEER") ///
	| strpos(jobtitle, "SCIEN") /// 
	| strpos(jobtitle, "RESEARCH") ///
	| strpos(jobtitle, "TECHNOLOGY DEVELOP") ///
	| strpos(jobtitle, "R&D") ///
	| strpos(jobtitle, "R& D") ///
	| strpos(jobtitle, "R &D") ///
	| strpos(jobtitle, "R & D") ///
	| strpos(jobtitle, "RDD ") 
bysort boardid ceoid termstartyr: egen revcnt_rd = sum(RDworker == 1)
bysort boardid ceoid termstartyr: egen revcnt_rdcur = sum(RDworker == 1 & iscurrentjob)
gen w_rd = 1/revcnt_rd
gen w_rdcur = 1/revcnt_rdcur
* set globals
global review = "approveceo iscurrentjob reviewgap"
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education nonUS"
global culture = "highincome_sd getahead_sd risktakinggps_sd patiencegps_sd"
global reviewsample = "revcnt_all > 49"
global rdreviewsample = "RDworker & revcnt_rd > 24 & revcnt_all > 49"
global cluster = "mainethcode"


//PREPARE TABLE
* PANEL A: All employees
eststo clear
eststo col1: /// baseline
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${reviewsample} [aw = w_all], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_all] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_all] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_all] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Baseline"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col1, addscalars(nofirms r(ndistinct))	
eststo col2: /// additional fixed effects
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${reviewsample} [aw = w_all], a(boardid reviewyear year) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_all] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_all] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_all] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Add FEs"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		estadd local yearFE         "X"
		distinct boardid if e(sample)
		eststo col2, addscalars(nofirms r(ndistinct))
eststo col3: /// positive reviews
	reghdfe trustsentiment_mtoe_pos trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${reviewsample} [aw = w_all], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_all] if e(sample)
		estadd scalar mean_pos r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		sum trustsentiment_mtoe_neg [aw = w_all] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_all] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd local spec           "Pos reviews"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col3, addscalars(nofirms r(ndistinct))
eststo col4: /// negative reviews
	reghdfe trustsentiment_mtoe_neg trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${reviewsample} [aw = w_all], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_all] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_all] if e(sample)
		estadd scalar mean_neg r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		sum trustsentiment_mtoe_abs [aw = w_all] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd local spec           "Neg reviews"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col4, addscalars(nofirms r(ndistinct))
eststo col5: /// current reviews
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${reviewsample} & iscurrentjob [aw = w_allcur], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_allcur] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_allcur] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_allcur] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Current revs"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col5, addscalars(nofirms r(ndistinct))
eststo col6: /// review count > 9
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if revcnt_all > 9 [aw = w_all], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_all] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_all] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_all] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Alt cutoff"
		estadd local cutoff         "10"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col6, addscalars(nofirms r(ndistinct))
eststo col7: /// review count > 24
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if revcnt_all > 24 [aw = w_all], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_all] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_all] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_all] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Alt cutoff"
		estadd local cutoff         "25"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col7, addscalars(nofirms r(ndistinct))
eststo col8: /// review count > 99
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if revcnt_all > 99 [aw = w_all], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_all] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_all] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_all] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Alt cutoff"
		estadd local cutoff         "100"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col8, addscalars(nofirms r(ndistinct))

esttab /*using "Table A16_Corporate trust culture robustness checks_Panel A.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(23) modelwidth(12) ///
	mgroups("Employee review's top down trust sentiment", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd) coeflab(trust_sd "CEO's trust") ///
	stats(mean_pos mean_neg ratio spec cutoff  controls baselineFE yearFE N nofirms, ///
		fmt(%9.3fc %9.3fc %9.3fc %9.0fc %9.0fc) ///
		lab("Positive reviews" "Negative reviews" "Normalized effect size" "Specification" "Minimum review count" ///
			"Baseline controls" "Firm \& Review year FEs" "Year being reviewed FEs" "Observations" "Firms"))


* PANEL B: R&D workers
eststo clear
eststo col1: /// baseline
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${rdreviewsample} [aw = w_rd], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rd] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rd] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rd] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Baseline"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col1, addscalars(nofirms r(ndistinct))
eststo col2: /// additional fixed effects
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${rdreviewsample} [aw = w_rd], a(boardid reviewyear year) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rd] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rd] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rd] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Add FEs"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		estadd local yearFE         "X"
		distinct boardid if e(sample)
		eststo col2, addscalars(nofirms r(ndistinct))
eststo col3: /// positive reviews
	reghdfe trustsentiment_mtoe_pos trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${rdreviewsample} [aw = w_rd], a(boardid reviewyear year) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rd] if e(sample)
		estadd scalar mean_pos r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rd] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rd] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd local spec           "Pos reviews"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sa`mple)
		eststo col3, addscalars(nofirms r(ndistinct))
eststo col4: /// negative reviews
	reghdfe trustsentiment_mtoe_neg trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${rdreviewsample} [aw = w_rd], a(boardid reviewyear year) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rd] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rd] if e(sample)
		estadd scalar mean_neg r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rd] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd local spec           "Neg reviews"
		estadd local controls       "X"
		estadd local baselineFE    "X"
		distinct boardid if e(sample)
		eststo col4, addscalars(nofirms r(ndistinct))
eststo col5: /// current reviews
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if ${rdreviewsample} & iscurrentjob [aw = w_rdcur], a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rdcur] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rdcur] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rdcur] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Current revs"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col5, addscalars(nofirms r(ndistinct))
eststo col6: /// review count > 9 & R&D review count > 4
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if RDworker & revcnt_rd > 4 & revcnt_all > 9 [aw = w_rd], ///
	a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rd] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rd] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rd] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Alt cutoff"
		estadd local cutoff1        "10"
		estadd local cutoff2        "5"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col6, addscalars(nofirms r(ndistinct))
eststo col7: /// review count > 24 & R&D review count > 9
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if RDworker & revcnt_rd > 9 & revcnt_all > 24 [aw = w_rd], ///
	a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rd] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rd] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rd] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Alt cutoff"
		estadd local cutoff1        "25"
		estadd local cutoff2        "10"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col7, addscalars(nofirms r(ndistinct))
eststo col8: /// review count > 99 & R&D review count > 49
	reghdfe trustsentiment_mtoe trust_sd ${review} ${firm} ${ceo} ${culture} ///
	if RDworker & revcnt_rd > 49 & revcnt_all > 99 [aw = w_rd], ///
	a(boardid reviewyear) cluster(${cluster}) keepsin
		sum trustsentiment_mtoe_pos [aw = w_rd] if e(sample)
		estadd scalar mean_pos r(mean)
		sum trustsentiment_mtoe_neg [aw = w_rd] if e(sample)
		estadd scalar mean_neg r(mean)
		sum trustsentiment_mtoe_abs [aw = w_rd] if e(sample)
		estadd scalar mean_abs r(mean)
		estadd scalar ratio _b[trust_sd]/r(mean)
		estadd local spec           "Alt cutoff"
		estadd local cutoff1        "100"
		estadd local cutoff2        "50"
		estadd local controls       "X"
		estadd local baselineFE     "X"
		distinct boardid if e(sample)
		eststo col8, addscalars(nofirms r(ndistinct))

esttab /*using "Table A16_Corporate trust culture robustness checks_Panel B.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(23) modelwidth(12) ///
	mgroups("Employee review's top down trust sentiment", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(trust_sd) ///
	stats(mean_pos mean_neg ratio spec cutoff1 cutoff2 controls baselineFE yearFE N nofirms, ///
		fmt(%9.3fc %9.3fc %9.3fc %9.0fc %9.0fc) ///
		lab("Positive reviews" "Negative reviews" "Normalized effect size" ///
			"Specification" "Minimum review count" "Min. R\&D review count" ///
			"Baseline controls" "Firm \& Review year FEs" "Year being reviewed FEs" "Observations" "Firms"))

cap log close

********************************************************************************
*           TABLE A17: CEO'S TRUST AND DIRECTOR SELECTION OVER TIME            *
********************************************************************************
cap log close
log using "Table A17_Director selection over time.log", replace

//PREPARE DATA
use "Director CEO firm year sample.dta", clear
* construct director type indicators
cap drop *dir
gen newdir = year == DIR_firstyear_key & year != DIR_lastyear_key & year != termendyr
gen leftdir = year == DIR_lastyear_key & year != termendyr & DIR_age < 75 //90th percentile in age at leaving board
gen remdir = DIR_firstyear_key < termstartyr & DIR_lastyear_key >= termendyr
bysort boardid ceoid termno directorid: egen NEWdir = max(newdir)
bysort boardid ceoid termno directorid: egen LEFTdir = max(leftdir)
bysort boardid ceoid termno directorid: egen REMdir = min(remdir)
* compute average trust by director type
cap drop *dirtrust
bysort boardid ceoid year: egen tempnew = mean(DIR_trust) if newdir
bysort boardid ceoid year: egen newdirtrust = mean(tempnew)
bysort boardid ceoid year: egen tempstay = mean(DIR_trust) if newdir & !LEFTdir
bysort boardid ceoid year: egen staydirtrust = mean(tempstay)
bysort boardid ceoid year: egen templeft = mean(DIR_trust) if leftdir
bysort boardid ceoid year: egen leftdirtrust = mean(templeft)
bysort boardid ceoid year: egen tempmean = mean(DIR_trust)
bysort boardid ceoid year: egen meandirtrust = mean(tempmean)
drop temp*
* compute director counts
bysort boardid ceoid year: egen countnew = sum(newdir)
bysort boardid ceoid year: egen countstay = sum(newdir & !LEFTdir)
bysort boardid ceoid year: egen countleft = sum(leftdir)
bysort boardid ceoid year: gen count = _N
* construct time period variables
cap drop timesinceCEO* timeperiod
gen timesinceCEO = min(year - termstartyr, 9)
gen timesinceCEO2 = timesinceCEO^2
gen timesinceCEO3 = timesinceCEO^3
gen timeperiod = 1 if inrange(timesinceCEO, 0, 2)
replace timeperiod = 2 if inrange(timesinceCEO, 3, 4)
replace timeperiod = 3 if inrange(timesinceCEO, 5, 6)
replace timeperiod = 4 if inrange(timesinceCEO, 7, 8)
replace timeperiod = 5 if timesinceCEO >= 9
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS & baselinesample"
global cluster = "mainethcode"


//PREPARE TABLE
eststo clear
* observation unit: directorid x boardid x ceoid x year
eststo col1: /// new directors
	reghdfe DIR_trust c.trust#i.timeperiod timesinceCEO* ${ceo} ${firm} ///
	if ${sample} & newdir, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "New"
		estadd local obsunit	"D-F-Y-CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// stayin directors
	reghdfe DIR_trust c.trust#i.timeperiod timesinceCEO* ${ceo} ${firm} ///
	if ${sample} & newdir & !LEFTdir, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Staying"
		estadd local obsunit	"D-F-Y-CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// leaving directors
	reghdfe DIR_trust c.trust#i.timeperiod timesinceCEO* ${ceo} ${firm} ///
	if ${sample} & leftdir, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Leaving"
		estadd local obsunit	"D-F-Y-CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
* observation unit: boardid x ceoid x year		
egen tagbrdceoyr = tag(boardid ceoid year)
eststo col4: /// new directors
	reghdfe newdirtrust c.trust#i.timeperiod timesinceCEO* ${ceo} ${firm} ///
	if ${sample} & tagbrdceoyr, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "New"
		estadd local obsunit	"F-Y-CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// staying directors
	reghdfe staydirtrust c.trust#i.timeperiod timesinceCEO* ${ceo} ${firm} ///
	if ${sample} & tagbrdceoyr, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Staying"
		estadd local obsunit	"F-Y-CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// leaving directors
	reghdfe leftdirtrust c.trust#i.timeperiod timesinceCEO* ${ceo} ${firm} ///
	if ${sample} & tagbrdceoyr, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "Leaving"
		estadd local obsunit	"F-Y-CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
eststo col7: /// all directors
	reghdfe meandirtrust c.trust#i.timeperiod timesinceCEO* ${ceo} ${firm} ///
	if ${sample} & tagbrdceoyr, a(boardid year) cluster(${cluster}) keepsin
		estadd local sample     "All"
		estadd local obsunit	"F-Y-CEO"
		estadd local FE         "X"
		estadd local controls   "X"
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))

global coeflist = "1.timeperiod#c.trust 2.timeperiod#c.trust 3.timeperiod#c.trust 4.timeperiod#c.trust 5.timeperiod#c.trust"
esttab /*using "Table A17_Director selection over time.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(25) ///
	mgroups("Individual director's trust" "Average director's trust", pattern(1 0 0 1 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist}) order(${coeflist}) ///
	coeflab(1.timeperiod#c.trust "Trust $\times$ 1(Tenure as CEO <= 2)" ///
			2.timeperiod#c.trust "Trust $\times$ 1(Tenure as CEO in [3, 4])" ///
			3.timeperiod#c.trust "Trust $\times$ 1(Tenure as CEO in [5, 6])" ///
			4.timeperiod#c.trust "Trust $\times$ 1(Tenure as CEO in [7, 8])" ///
			5.timeperiod#c.trust "Trust $\times$ 1(Tenure as CEO >= 9)") ///
	stats(sample obsunit FE controls N nofirms, fmt(%9.0fc %9.0fc) ///
		lab("Director sample" "Observation unit" "Firm \& Year FEs" "Baseline controls" "Observations" "Firms"))

cap log close

********************************************************************************
*        TABLE A18: EFFECTS OF CEO'S TRUST ON FIRM'S FUTURE PERFORMANCE        *
********************************************************************************
cap log close
log using "Table A18_Effect on future performance.log", replace

//PREPARE DATA
use "CEO transition event sample.dta", clear
* set globals
global firm = "firmage firmage2 ash_xrd"
global ceo = "gender age age2 yrinco i.education"
global eventsample = "!bothnonUS"
global cluster = "mainethcode"


//PREPARE TABLE
* PANEL A:
eststo clear 
eststo col1: /// future sales
	reghdfe f2logsale c.trust_sd##c.resqual ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col1, add(noevents r(ndistinct))
eststo col2: /// future employment
	reghdfe f2logemp c.trust_sd##c.resqual ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col2, add(noevents r(ndistinct))
eststo col3: /// future capital
	reghdfe f2logcapital c.trust_sd##c.resqual ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col3, add(noevents r(ndistinct))
eststo col4: /// future TFP (computed from K, L)
	reghdfe f2TFP_KL c.trust_sd##c.resqual ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col4, add(noevents r(ndistinct))
eststo col5: /// future TFP (computed from K, L, M)
	reghdfe f2TFP_KLM c.trust_sd##c.resqual ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col5, add(noevents r(ndistinct))
eststo col6: /// future Tobin's Q
	reghdfe f2tobinQ c.trust_sd##c.resqual ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col6, add(noevents r(ndistinct))

lab var f2logsale       "ln(sales)"
lab var f2logemp        "ln(employment)"
lab var f2logcapital    "ln(capital)"
lab var f2TFP_KL        "TFP(KL)"
lab var f2TFP_KLM       "TFP(KLM)"
lab var f2tobinQ        "Tobin's Q"
esttab /*using "Table A18_Effect on future performance_Panel A.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	collabels(none) label varwidth(33) modelwidth(12) ///
	keep(trust_sd c.trust_sd#c.resqual) order(trust_sd c.trust_sd#c.resqual) ///
	coeflab(trust_sd "CEO's trust" c.trust_sd#c.resqual "Trust $\times$ Researcher quality") ///
	stats(FE controls N noevents, fmt(%9.0fc %9.0fc) ///
		lab("Event \& Year FEs" "Baseline controls" "Observations" "Events"))


* PANEL B:
eststo clear 
eststo col1: /// future sales
	reghdfe f2logsale c.trust_sd#i.resqualpct ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col1, add(noevents r(ndistinct))	
eststo col2: /// future employment
	reghdfe f2logemp c.trust_sd#i.resqualpct ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col2, add(noevents r(ndistinct))	
eststo col3: /// future capital
	reghdfe f2logcapital c.trust_sd#i.resqualpct ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col3, add(noevents r(ndistinct))
eststo col4: /// future TFP (computed from K, L)
	reghdfe f2TFP_KL c.trust_sd#i.resqualpct ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col4, add(noevents r(ndistinct))
eststo col5: /// future TFP (computed from K, L, M)
	reghdfe f2TFP_KLM c.trust_sd#i.resqualpct ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col5, add(noevents r(ndistinct))
eststo col6: /// future Tobin's Q
	reghdfe f2tobinQ c.trust_sd#i.resqualpct ${firm} ${ceo} if ${eventsample}, ///
	a(eventid year) cluster(${cluster}) keepsin
		estadd local FE         "X"
		estadd local controls   "X"
		distinct eventid if e(sample)
		eststo col6, add(noevents r(ndistinct))

lab var f2logsale       "ln(sales)"
lab var f2logemp        "ln(employment)"
lab var f2logcapital    "ln(capital)"
lab var f2TFP_KL        "TFP(KL)"
lab var f2TFP_KLM       "TFP(KLM)"
lab var f2tobinQ        "Tobin's Q"
global coeflist = "1.resqualpct#c.trust_sd 2.resqualpct#c.trust_sd 3.resqualpct#c.trust_sd 4.resqualpct#c.trust_sd 5.resqualpct#c.trust_sd"
esttab /*using "Table A18_Effet on future performance_Panel B.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	collabels(none) label varwidth(32) modelwidth(12) ///
	keep(${coeflist}) order(${coeflist}) ///
	coeflab(1.resqualpct#c.trust_sd "Trust $\times$ Quality quintile 1" ///
			2.resqualpct#c.trust_sd "Trust $\times$ Quality quintile 2" ///
			3.resqualpct#c.trust_sd "Trust $\times$ Quality quintile 3" ///
			4.resqualpct#c.trust_sd "Trust $\times$ Quality quintile 4" ///
			5.resqualpct#c.trust_sd "Trust $\times$ Quality quintile 5") ///
	stats(FE controls N noevents, fmt(%9.0fc %9.0fc) ///
		lab("Event \& Year FEs" "Baseline controls" "Observations" "Events"))

cap log close

********************************************************************************
*TABLE A19: ROBUSTNESS CHECKS FOR CEO'S TRUST EFFECT IN BILATERAL TRUST SAMPLE *
********************************************************************************
cap log close
log using "Table A19_Bilateral trust robustness checks.log", replace

//PREPARE DATA
use "Bilateral trust sample_nonUS.dta", clear
* construct additional variables
gen pharmachem = inlist(sector, ///
	"Chemicals", ///
	"Pharmaceuticals and Biotechnology", ///
	"Health")
gen electroit = inlist(sector, ///
	"Electronic & Electrical Equipment", ///
	"Information Technology Hardware", ///
	"Software & Computer Services")
gen ind = 1 * pharma + 2 * electroit + 3 * (1-pharmachem) * (1-electroit)
gen postgradnonMBA = (education == 3 & MBA == 0) | education == 4
gen hasRDexp = preCEO_resdir == 1 | preCEO_techdir == 1
* set globals
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global bitrustFEs = "ceoid eubmcode boardid#year"
global bitrustsample = "eubmcode != 33 & haspat & year < 2012 & !nonUS" //eubmcode 33 = US
global bitrustsample_ext = "eubmcode != 33 & haspat_ext & year < 2015 & !nonUS" //eubmcode 33 = US
global cluster = "etheubmcode"
* set sample
qui reghdfe ash_f1allpatxc bitrust_sd logat logsale ${firm} ${ceo} if ${bitrustsample}, ///
	a(boardid eubmcode ceoid year) keepsin
gen bitrustsample = e(sample)
qui reghdfe ash_f1allpatxc bitrust logat logsale ${firm} ${ceo} if ${bitrustsample_ext}, ///
	a(boardid eubmcode ceoid year) keepsin
gen bitrustsample_ext = e(sample)


//PREPARE TABLE	
* PANEL A: Alternative clustering schemes and time lags before patent filing
eststo clear
eststo col1: /// cluster by CEO's main ethnicity
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(mainethcode) keepsin
		estadd local cluster 	"Main eth"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// clustet by CEO
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(ceoid) keepsin
		estadd local cluster 	"CEO"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// cluster by inventor country
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(eubmcode) keepsin
		estadd local cluster 	"Inv country"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// cluster by firm
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(boardid) keepsin
		estadd local cluster 	"Firm"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// 0-year foward patents
	reghdfe ash_allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(${cluster}) keepsin
		estadd local forward 	"0-year"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// 2-year forward patents
	reghdfe ash_f2allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(${cluster}) keepsin
		estadd local forward 	"2-year"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
eststo col7: /// 3-year forward patents
	reghdfe ash_f3allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(${cluster}) keepsin
		estadd local forward 	"3-year"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))

esttab /*using "Table A19_Bilateral trust robustness checks_Panel A.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(27) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(bitrust_sd) coeflab(bitrust_sd "CEO's bilateral trust") ///
	stats(cluster forward FE_CEO FE_IC FE_FxY N nofirmxcntrys nofirms, fmt(%9.0fc %9.0fc %9.0fc) ///
		lab("Clustering scheme" "Forward" "CEO FEs" "Inventor country FEs"  "Firm $\times$ Year FEs" ///
			   "Observations" "Firm $\times$ Inv country's" "Firms"))


* PANEL B: Alternative sample restrictions and bilateral trust effect by industry and CEO's characteristics	
eststo clear
eststo col1: /// excluding singletons
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
	a(${bitrustFEs}) cluster(${cluster})
		estadd local sampincl   "Singletons"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// excluding female CEOs
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample & gender != 2, ///
	a(${bitrustFEs}) cluster(${cluster}) keepsin
		estadd local sampincl   "Female CEOs"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
eststo col3: /// excluding interim CEOs
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample & !interimCEO, ///
	a(${bitrustFEs}) cluster(${cluster})
		estadd local sampincl   "Interim CEOs"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// 2000-2014
	reghdfe ash_f1allpatxc bitrust_sd if bitrustsample_ext, ///
	a(${bitrustFEs}) cluster(${cluster})
		estadd local sampper   	"2000-14"
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))
eststo col5: /// by industry
	reghdfe ash_f1allpatxc c.bitrust_sd#i.ind if bitrustsample, ///
	a(${bitrustFEs}) cluster(${cluster}) keepsin
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// by CEO's education
	reghdfe ash_f1allpatxc c.bitrust_sd#i.postgradnonMBA if bitrustsample, ///
	a(${bitrustFEs}) cluster(${cluster}) keepsin
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
eststo col7: /// by CEO's experience
	reghdfe ash_f1allpatxc c.bitrust_sd#i.hasRDexp if bitrustsample, ///
	a(${bitrustFEs}) cluster(${cluster}) keepsin	
		estadd local FE_CEO     "X"
		estadd local FE_IC      "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))

global coeflist1 = "bitrust_sd 1.ind#c.bitrust_sd 2.ind#c.bitrust_sd 3.ind#c.bitrust_sd"
global coeflist2 = "0.postgradnonMBA#c.bitrust_sd 1.postgradnonMBA#c.bitrust_sd"
global coeflist3 = "0.hasRDexp#c.bitrust_sd 1.hasRDexp#c.bitrust_sd"
esttab /*using "Table A19_Bilateral trust robustness checks_Panel B.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(42) modelwidth(12) ///
	mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(${coeflist1} ${coeflist2} ${coeflist3}) order(${coeflist1} ${coeflist2} ${coeflist3}) ///
	coeflab(bitrust_sd "CEO's bilateral trust" ///
			1.ind#c.bitrust_sd "Bilateral trust $\times$ Pharma/chemical" ///
			2.ind#c.bitrust_sd "Bilateral trust $\times$ ICT/electronic" ///
			3.ind#c.bitrust_sd "Bilateral trust $\times$ Other industries" ///
			0.postgradnonMBA#c.bitrust_sd "Bilateral trust $\times$ MBA/no grad deg" ///
			1.postgradnonMBA#c.bitrust_sd "Bilateral trust $\times$ Non-MBA grad deg" ///
			0.hasRDexp#c.bitrust_sd "Bilateral trust $\times$ No prior R\&D exp" ///
			1.hasRDexp#c.bitrust_sd "Bilateral trust $\times$ Prior R\&D exp") ///
	stats(sampincl sampper FE_CEO FE_IC FE_FxY N nofirmxcntrys nofirms, fmt(%9.0fc %9.0fc %9.0fc) ///
		lab("Sample including" "Sample period" "CEO FEs" "Inventor country FEs" ///
				"Firm $\times$ Year FEs" "Observations" "Firm $\times$ Inv country's" "Firms"))

cap log close

********************************************************************************
*      TABLE A20: CEO'S TRUST EFFECT IN EXTENDED BILATERAL TRUST SAMPLES       *
********************************************************************************
cap log close
log using "Table A20_Effect in extended bilateral trust sample.log", replace

//PREPARE DATA 
* set globals
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global bitrustFEs = "ceoid eubmcode boardid#year"
global bitrustsample = "eubmcode != 33 & haspat & year < 2012 & !nonUS" //eubmcode 33 = US
global cluster = "etheubmcode"


//PREPARE TABLE
foreach panel in "A" "B" {
	* PANEL A: All inventor bilateral trust sample
	if "`panel'" == "A" {
		use "Bilateral trust sample_all.dta", clear
	}
	* PANEL B: US-based inventor bilateral trust sample
	if "`panel'" == "B" {
		use "Bilateral trust sample_US.dta", clear
	}
	
	* construct additional variables
	gen sameethnic = eubmcode == mainethcode & mainethshare >= 0.8	
	* set sample
	qui reghdfe ash_f1allpatxc bitrust_sd logat logsale ${firm} ${ceo} if ${bitrustsample}, ///
		a(boardid eubmcode ceoid year) keepsin
	gen bitrustsample = e(sample)
	
	eststo clear
	eststo col1: /// baseline
		reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local spec       "Baseline"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct boardid if e(sample)
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col1, add(nofirms r(ndistinct))
	eststo col2: /// additional fixed effects
		reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
		a(boardid#year ceoid#year eubmcode#year) cluster(${cluster}) keepsin
			estadd local spec       "Add FEs"
			estadd local FE_FxY     "X"
			estadd local FE_CEOxY   "X"
			estadd local FE_ICxY    "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col2, add(nofirms r(ndistinct))
	eststo col3: /// additional fixed effects
		reghdfe ash_f1allpatxc bitrust_sd ${firm} ${ceo} if bitrustsample, ///
		a(ceoid boardid#eubmcode year) cluster(${cluster}) keepsin
			estadd local spec       "Add FEs"
			estadd local FE_CEO     "X"
			estadd local FE_FxIC    "X"
			estadd local FE_Y       "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col3, add(nofirms r(ndistinct))
	eststo col4: /// forward citation-weighted
		reghdfe ash_f1allpatxc_citff bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin 
			estadd local spec       "Fwd cites"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col4, add(nofirms r(ndistinct))
	eststo col5: /// exclude same ethnicity
		reghdfe ash_f1allpatxc bitrust_sd if bitrustsample & !sameethnic, ///
		a(${bitrustFEs}) cluster(${cluster})
			estadd local spec       "Pair ctrls"
			estadd local exclsame   "X"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col5, add(nofirms r(ndistinct))
	eststo col6: /// common language control
		reghdfe ash_f1allpatxc bitrust_sd comlang_ethno if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local spec       "Pair ctrls"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col6, add(nofirms r(ndistinct))
	eststo col7: /// geographical distance control
		reghdfe ash_f1allpatxc bitrust_sd distw if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local spec       "Pair ctrls"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col7, add(nofirms r(ndistinct))
	eststo col8: /// genetic distance control
		reghdfe ash_f1allpatxc bitrust_sd fstdist_wt if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local spec       "Pair ctrls"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col8, add(nofirms r(ndistinct))
	
	global coeflist = "bitrust_sd comlang_ethno distw fstdist_wt"
	esttab /*using "Table A20_Effect in extended bilateral trust sample_Panel `panel'.tex"*/, ///
		cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
		nomtitle collabels(none) label varwidth(32) modelwidth(12) ///
		mgroups("\arsinh(Future patent applications)", pattern(1 0 0 0 0 0 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		keep(${coeflist}) order(${coeflist}) ///
		coeflab(bitrust_sd "CEO's bilateral trust" ///
				comlang_ethno "Common language dummy" ///
				distw "Geographical distance (1000km)" ///
				fstdist_wt "Genetic distance (z-score)") ///
		stats(spec FE_CEO FE_IC FE_FxY FE_CEOxY FE_ICxY FE_FxIC FE_Y exclsame N nofirmxcntrys nofirms, ///
			fmt(%9.0fc %9.0fc %9.0fc) ///
			lab("Specification" "CEO FEs" "Inventor country FEs" "Firm $\times$ Year FEs" "CEO $\times$ Year FEs" ///
				"Inv country $\times$ Year FEs" "Firm $\times$ Inv country's FEs" "Year FEs" ///
				"Excl same-country pairs" "Observations" "Firm $\times$ Inv country's" "Firms"))
}

cap log close

********************************************************************************
*     TABLE A21: CEO'S BILATERAL TRUST EFFECT ON QUALITY-WEIGHTED PATENTS      * 
********************************************************************************
cap log close
log using "Table A21_Bilateral trust quality-weighted patents.log", replace

//PREPARE DATA
* set globals
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global bitrustFEs = "ceoid eubmcode boardid#year"
global bitrustsample = "eubmcode != 33 & haspat & year < 2012 & !nonUS" //eubmcode 33 = US
global cluster = "etheubmcode"


//PREPARE TABLE
foreach panel in "A" "B" {
	* PANEL A: Non-US-based inventor bilateral trust sample
	if "`panel'" == "A" {
		use "Bilateral trust sample_nonUS.dta", clear
	}
	* PANEL B: All inventor bilateral trust sample
	if "`panel'" == "B" {
		use "Bilateral trust sample_all.dta", clear
	}
	* construct additional variables
	forval i = 1/4 {
		gen ash_f1allpatxc_citff_q`i' = asinh(f1allpatxc_citff_q`i') 
	}
	gen ash_f1avgcitff = asinh(f1allpatxc_citff/f1allpatxc)
	replace ash_f1avgcitff = 0 if f1allpatxc == 0
	* set sample
	qui reghdfe ash_f1allpatxc bitrust_sd logat logsale ${firm} ${ceo} if ${bitrustsample}, ///
		a(boardid eubmcode ceoid year) keepsin
	gen bitrustsample = e(sample)
	
	eststo clear
	eststo col1: /// bottom-quartile-citation patents
		reghdfe ash_f1allpatxc_citff_q1 bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col1, add(nofirms r(ndistinct))
	eststo col2: /// 2nd-quartile-citation patents
		reghdfe ash_f1allpatxc_citff_q2 bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col2, add(nofirms r(ndistinct))
	eststo col3: /// 3rd-quartile-citation patents
		reghdfe ash_f1allpatxc_citff_q3 bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col3, add(nofirms r(ndistinct))
	eststo col4: /// top-quartile-citation patents
		reghdfe ash_f1allpatxc_citff_q4 bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col4, add(nofirms r(ndistinct))
	eststo col5: /// backward NPL citation-weighted
		reghdfe ash_f1allpatxc_npl bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col5, add(nofirms r(ndistinct))
	eststo col6: /// technological scope-weighted
		reghdfe ash_f1allpatxc_sco bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin 
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col6, add(nofirms r(ndistinct))
	eststo col7: /// granted USPTO patents
		reghdfe ash_f1uspatxc_granted bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col7, add(nofirms r(ndistinct))
	eststo col8: /// average forward citations
		reghdfe ash_f1avgcitff bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col8, add(nofirms r(ndistinct))
	
	label var ash_f1allpatxc_citff_q1   "Bottom quartile"
	label var ash_f1allpatxc_citff_q2   "Second quartile"
	label var ash_f1allpatxc_citff_q3   "Third quartile"
	label var ash_f1allpatxc_citff_q4   "Top quartile"
	label var ash_f1allpatxc_npl        "Backward NPL cites"
	label var ash_f1allpatxc_sco        "Tech scope"
	label var ash_f1uspatxc_granted     "Granted USPTO"
	label var ash_f1avgcitff            "Average cites"
	esttab /*using "Table A21_Bilateral trust quality-weighted patents_Panel `panel'.tex"*/, ///
		cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
		collabels(none) label varwidth(27) modelwidth(12) ///
		mgroups("arsinh(Future quality-weighted patents)", pattern(1 0 0 0 0 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		keep(bitrust_sd) coefla(bitrust_sd "CEO's bilateral trust") ///
		stats(FE_CEO FE_IC FE_FxY  N nofirmxcntrys nofirms, fmt(%9.0fc %9.0fc %9.0fc) ///
			lab("CEO FEs" "Inventor country FEs" "Firm $\times$ Year FEs" ///
				"Observations" "Firm $\times$ Inv country's" "Firms"))
}

cap log close

********************************************************************************
*              TABLE A22: MARGINS OF CEO'S BILATERAL TRUST EFFECT              *
********************************************************************************
cap log close
log using "Table A22_Bilateral trust margins.log", replace

//PREPARE DATA
* set globals
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global bitrustFEs = "ceoid eubmcode boardid#year"
global bitrustsample = "eubmcode != 33 & haspat & year < 2012 & !nonUS" //eubmcode 33 = US
global cluster = "etheubmcode"

//PREPARE TABLE
foreach panel in "A" "B" {
	* Panel A: Non-US-based inventor bilateral trust sample
	if "`panel'" == "A" {
		global sample = "nonUS"
	}
	* Panel B: All inventor bilateral trust sample
	if "`panel'" == "B" {
		global sample = "all"
	}
	
	eststo clear
	* prepare data for column (1)
	use "Bilateral trust sample_${sample}.dta", clear
	qui reghdfe ash_f1allpatxc bitrust_sd logat logsale ${firm} ${ceo} if ${bitrustsample}, ///
		a(boardid eubmcode ceoid year) keepsin
	keep if e(sample)
	keep boardid year
	duplicates drop 
	tempfile bitrustsample
	save "`bitrustsample'"
	use "Baseline CEO firm year sample.dta", clear
	merge m:1 boardid year using "`bitrustsample'"	
	bysort boardid: egen bitrustsample = max(_m == 3)
	
	eststo col1: /// generalized trust in firm x year sample
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} ///
		if year < 2012 & !nonUS & bitrustsample, a(boardid year) cluster(mainethcode) keepsin
			estadd local sample     "Gen trust"
			estadd local transform  "arsinh(.)"
			estadd local FE_FnY     "X"
			distinct boardid if e(sample)
			eststo col1, add(nofirms r(ndistinct))
	
	* prepare data for columns (2)-(9)
	use "Bilateral trust sample_${sample}.dta", clear
	gen D_f1allpatxc = f1allpatxc > 0
	bysort boardid ceoid: egen minCEOyr = min(year)
	bysort boardid ceoid: egen maxCEOyr = max(year)
	qui reghdfe ash_f1allpatxc bitrust_sd logat logsale ${firm} ${ceo} if ${bitrustsample}, ///
		a(boardid eubmcode ceoid year) keepsin
	gen bitrustsample = e(sample)
	
	eststo col2: /// baseline bilateral trust effect
		reghdfe ash_f1allpatxc bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local sample     "Full"
			estadd local transform  "arsinh(.)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col2, add(nofirms r(ndistinct))
	eststo col3: /// baseline bilateral trust effect
		reghdfe D_f1allpatxc bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			sum D_f1allpatxc if e(sample)
			estadd scalar depvarmean = r(mean)
			estadd local sample     "Full"
			estadd local transform  "1(.>0)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col3, add(nofirms r(ndistinct))
	eststo col4: /// patenting period
		reghdfe ash_f1allpatxc bitrust_sd if bitrustsample ///
		& inrange(year, firstpatyear-1, lastpatyear), a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local sample     "Patent"
			estadd local transform  "arsinh(.)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col4, add(nofirms r(ndistinct))
	eststo col5: /// patenting years
		reghdfe log_f1allpatxc bitrust_sd if bitrustsample, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local sample     "Patent"
			estadd local transform  "ln(.)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"		
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col5, add(nofirms r(ndistinct))
	eststo col6: /// bilateral trust effect intensive margin
		reghdfe ash_f1allpatxc bitrust_sd if bitrustsample & minCEOyr > firstpatyear, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local sample     "Intensive"
			estadd local transform  "arsinh(.)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col6, add(nofirms r(ndistinct))
	eststo col7: /// bilateral trust effect intensive margin
		reghdfe D_f1allpatxc bitrust_sd if bitrustsample & minCEOyr > firstpatyear, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			sum D_f1allpatxc if e(sample)
			estadd scalar depvarmean = r(mean)
			estadd local sample     "Intensive"
			estadd local transform  "1(.>0)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col7, add(nofirms r(ndistinct))
	eststo col8: /// bilateral trust effect extensive margin
		reghdfe ash_f1allpatxc bitrust_sd if bitrustsample & minCEOyr <= firstpatyear, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local sample     "Extensive"
			estadd local transform  "arsinh(.)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col8, add(nofirms r(ndistinct))
	eststo col9: /// bilateral trust effect extensive margin
		reghdfe D_f1allpatxc bitrust_sd if bitrustsample & minCEOyr <= firstpatyear, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			sum D_f1allpatxc if e(sample)
			estadd scalar depvarmean = r(mean)
			estadd local sample     "Extensive"
			estadd local transform  "1(.>0)"
			estadd local FE_CEO     "X"
			estadd local FE_IC      "X"
			estadd local FE_FxY     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col9, add(nofirms r(ndistinct))
	
	esttab /*using "Table A22_Bilateral trust margins_Panel `panel'.tex"*/, ///
		cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
		nomtitle collabels(none) label varwidth(27) modelwidth(12) ///
		mgroups("Future patent applications", pattern(1 0 0 0 0 0 0 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		keep(trust_sd bitrust_sd) order(trust_sd bitrust_sd) ///
		coeflab(trust_sd "CEO's generalized trust" bitrust_sd "CEO's bilateral trust") ///
		stats(depvarmean sample transform FE_FnY FE_FxY FE_CEO FE_IC N nofirmxcntrys nofirms, fmt(%9.3fc %9.0fc) ///
			lab("Dep. var. mean" "Sample" "Transformation" "Firm \& Year FEs" "Firm $\times$ Year FEs" ///
				"CEO FEs" "Inventor country FEs" "Observations" "Firm $\times$ Inv country's" "Firms"))
}

cap log close

********************************************************************************
*            TABLE A23: DIRECTIONS OF CEO-INVENTOR BILATERAL TRUST             *
********************************************************************************
cap log close
log using "Table A23_Bilateral trust directions.log", replace

//PREPARE DATA
* set globals
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global bitrustFEs = "ceoid eubmcode boardid#year"
global bitrustsample = ///
	"eubmcode != 33 & haspat & year < 2012 & !nonUS & bitrust != . & bitrusted != ." //eubmcode 33 = US
global cluster = "etheubmcode"
	

//PREPARE TABLE
foreach panel in "A" "B" {
	* PANEL A: Non-US-based inventor bilateral trust sample
	if "`panel'" == "A" {
		use "Bilateral trust sample_nonUS.dta", clear
	}
	* PANEL B: All inventor bilateral trust sample
	if "`panel'" == "B" {
		use "Bilateral trust sample_all.dta", clear
	}
	* construct additional variables
	egen pctbitrust = xtile(bitrust) if ${bitrustsample}, n(10)
	egen pctbitrusted = xtile(bitrusted) if ${bitrustsample}, n(10) 
	
	eststo clear
	eststo col1: /// CEO-to-inventors trust (bitrust)
		reghdfe ash_f1allpatxc bitrust_sd if ${bitrustsample}, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local weight			"Pat count"
			estadd local FE_CEO         "X"
			estadd local FE_IC          "X"
			estadd local FE_FxY         "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col1, add(nofirms r(ndistinct))
	eststo col2: /// CEO-to-inventors trust with bitrusted decile FEs
		reghdfe ash_f1allpatxc bitrust_sd if ${bitrustsample}, ///
		a(${bitrustFEs} pctbitrusted) cluster(${cluster}) keepsin
			estadd local weight			"Pat count"
			estadd local FE_CEO         "X"
			estadd local FE_IC          "X"
			estadd local FE_FxY         "X"
			estadd local FE_bitrusted   "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col2, add(nofirms r(ndistinct))
	eststo col3: /// inventors-to-CEO trust (bitrusted)
		reghdfe ash_f1allpatxc bitrusted_sd if ${bitrustsample}, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local weight			"Pat count"
			estadd local FE_CEO         "X"
			estadd local FE_IC          "X"
			estadd local FE_FxY         "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col3, add(nofirms r(ndistinct))
	eststo col4: /// inventors-to-CEO trust with bitrust decile FEs
		reghdfe ash_f1allpatxc bitrusted_sd if ${bitrustsample}, ///
		a(${bitrustFEs} pctbitrust) cluster(${cluster}) keepsin
			estadd local weight			"Pat count"
			estadd local FE_CEO         "X"
			estadd local FE_IC          "X"
			estadd local FE_FxY         "X"
			estadd local FE_bitrust     "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col4, add(nofirms r(ndistinct))
	eststo col5: /// both bilateral trust directions
		reghdfe ash_f1allpatxc bitrust_sd bitrusted_sd if ${bitrustsample}, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local weight			"Pat count"
			estadd local FE_CEO         "X"
			estadd local FE_IC          "X"
			estadd local FE_FxY         "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col5, add(nofirms r(ndistinct))
	eststo col6: /// both bilateral trust directions, citation-weighted
		reghdfe ash_f1allpatxc_citff bitrust_sd bitrusted_sd if ${bitrustsample}, ///
		a(${bitrustFEs}) cluster(${cluster}) keepsin
			estadd local weight			"Fwd cites"
			estadd local FE_CEO         "X"
			estadd local FE_IC          "X"
			estadd local FE_FxY         "X"
			distinct brdeubmcode if e(sample)
			estadd scalar nofirmxcntrys = r(ndistinct)
			distinct boardid if e(sample)
			eststo col6, add(nofirms r(ndistinct))
	
	esttab /*using "Table A23_Bilateral trust directions_Panel `panel.tex"*/, ///
		cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
		nomtitle collabels(none) label varwidth(36) modelwidth(12) ///
		mgroups("arsinh(Future patent applications)", pattern(1 0 0 0 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
		keep(bitrust_sd bitrusted_sd) order(bitrust_sd bitrusted_sd) ///
		coeflab(bitrust_sd "CEO-toward-inventors bilateral trust" ///
				bitrusted_sd "Inventors-toward-CEO bilateral trust") ///
		stats(weight FE_CEO FE_IC FE_FxY FE_bitrusted FE_bitrust N nofirmxcntrys nofirms, ///
		fmt(%9.0fc %9.0fc %9.0fc) ///
			lab("Quality weight" "CEO FEs" "Inventor country FEs" "Firm $\times$ Year FEs" ///
				"Inventor-to-CEO trust decile FEs" "CEO-to-inventor trust decile FEs" ///
				"Observations" "Firm $\times$ Inv country's" "Firms"))
}

cap log close

********************************************************************************
*           TABLE A24: CEO'S BILATERAL TRUST AND DIRECTOR SELECTION            *
********************************************************************************
cap log close
log using "Table A24_Bilateral trust and director selection.log", replace

//PREPARE DATA
* set globals
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global sample = "eubmcode != 33 & haspat & year < 2012 & !nonUS & bitrustsample" //eubmcode 33 = US
global cluster = "etheubmcode"

//PREPARE TABLE
eststo clear
* prepare data for columns (1)-(4)
use "Director bilateral trust sample_nonUS.dta", clear
*** construct director type indicators
cap drop *dir
gen newdir = year == DIR_firstyear_key & year != DIR_lastyear_key & year != termendyr
gen leftdir = year == DIR_lastyear_key & year != termendyr & DIR_age < 75 //90th percentile in age at leaving board
gen remdir = DIR_firstyear_key < termstartyr & DIR_lastyear_key >= termendyr
bysort boardid ceoid termno directorid: egen NEWdir = max(newdir)
bysort boardid ceoid termno directorid: egen LEFTdir = max(leftdir)
bysort boardid ceoid termno directorid: egen REMdir = min(remdir)
*** compute average trust by director type
cap drop *dirtrust
bysort boardid eubmcode ceoid year: egen tempnew = mean(DIR_bitrust) if newdir
bysort boardid eubmcode ceoid year: egen newdirtrust = mean(tempnew)
bysort boardid eubmcode ceoid year: egen tempstay = mean(DIR_bitrust) if newdir & !LEFTdir
bysort boardid eubmcode ceoid year: egen staydirtrust = mean(tempstay)
bysort boardid eubmcode ceoid year: egen templeft = mean(DIR_bitrust) if leftdir
bysort boardid eubmcode ceoid year: egen leftdirtrust = mean(templeft)
bysort boardid eubmcode ceoid year: egen tempmean = mean(DIR_bitrust)
bysort boardid eubmcode ceoid year: egen meandirtrust = mean(tempmean)
drop temp*

eststo col1: /// new directors
	reghdfe DIR_bitrust bitrust ${firm} ${ceo} if ${sample} & newdir, ///
	a(boardid eubmcode year) cluster(${cluster}) keepsin
		estadd local sample     "Non-US invs"
		estadd local dirtrust   "Individual"
		estadd local dirsample  "New dirs"
		estadd local FE_F 		"X"
		estadd local FE_IC 		"X"
		estadd local FE_Y 		"X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col1, add(nofirms r(ndistinct))
eststo col2: /// new directors
	reghdfe DIR_bitrust bitrust if ${sample} & newdir, ///
	a(ceoid eubmcode boardid#year) cluster(${cluster}) keepsin
		estadd local sample     "Non-US invs"
		estadd local dirtrust   "Individual"
		estadd local dirsample  "New dirs"
		estadd local FE_IC      "X"
		estadd local FE_CEO     "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col2, add(nofirms r(ndistinct))
egen tagbrdeubmceoyr = tag(boardid eubmcode ceoid year)
eststo col3: /// all directors
	reghdfe meandirtrust bitrust ${firm} ${ceo} if ${sample} & tagbrdeubmceoyr, ///
	a(boardid eubmcode year) cluster(${cluster}) keepsin
		estadd local sample     "Non-US invs"
		estadd local dirtrust   "Average"
		estadd local dirsample  "All dirs"
		estadd local FE_F 		"X"
		estadd local FE_IC 		"X"
		estadd local FE_Y 		"X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col3, add(nofirms r(ndistinct))
eststo col4: /// all directors
	reghdfe meandirtrust bitrust if ${sample} & tagbrdeubmceoyr, ///
	a(ceoid eubmcode boardid#year) cluster(${cluster}) keepsin
		estadd local sample     "Non-US invs"
		estadd local dirtrust   "Average"
		estadd local dirsample  "All dirs"
		estadd local FE_IC      "X"
		estadd local FE_CEO     "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col4, add(nofirms r(ndistinct))

* prepare data for columns (5)-(8)
use "Director bilateral trust sample_all.dta", clear
*** construct director type indicators
cap drop *dir
gen newdir = year == DIR_firstyear_key & year != DIR_lastyear_key & year != termendyr
gen leftdir = year == DIR_lastyear_key & year != termendyr & DIR_age < 75 //90th percentile in age at leaving board
gen remdir = DIR_firstyear_key < termstartyr & DIR_lastyear_key >= termendyr
bysort boardid ceoid termno directorid: egen NEWdir = max(newdir)
bysort boardid ceoid termno directorid: egen LEFTdir = max(leftdir)
bysort boardid ceoid termno directorid: egen REMdir = min(remdir)
*** compute average trust by director type
cap drop *dirtrust
bysort boardid eubmcode ceoid year: egen tempnew = mean(DIR_bitrust) if newdir
bysort boardid eubmcode ceoid year: egen newdirtrust = mean(tempnew)
bysort boardid eubmcode ceoid year: egen tempstay = mean(DIR_bitrust) if newdir & !LEFTdir
bysort boardid eubmcode ceoid year: egen staydirtrust = mean(tempstay)
bysort boardid eubmcode ceoid year: egen templeft = mean(DIR_bitrust) if leftdir
bysort boardid eubmcode ceoid year: egen leftdirtrust = mean(templeft)
bysort boardid eubmcode ceoid year: egen tempmean = mean(DIR_bitrust)
bysort boardid eubmcode ceoid year: egen meandirtrust = mean(tempmean)
drop temp*

eststo col5: /// new directors
	reghdfe DIR_bitrust bitrust ${firm} ${ceo} if ${sample} & newdir, ///
	a(boardid eubmcode year) cluster(${cluster}) keepsin
		estadd local sample     "All invs"
		estadd local dirtrust   "Individual"
		estadd local dirsample  "New dirs"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col5, add(nofirms r(ndistinct))
eststo col6: /// new directors
	reghdfe DIR_bitrust bitrust if ${sample} & newdir, ///
	a(ceoid eubmcode boardid#year) cluster(${cluster}) keepsin
		estadd local sample     "All invs"
		estadd local dirtrust   "Individual"
		estadd local dirsample  "New dirs"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col6, add(nofirms r(ndistinct))
egen tagbrdeubmceoyr = tag(boardid eubmcode ceoid year)
eststo col7: /// all directors
	reghdfe meandirtrust bitrust ${firm} ${ceo} if ${sample} & tagbrdeubmceoyr, ///
	a(boardid eubmcode year) cluster(${cluster}) keepsin	
		estadd local sample     "All invs"
		estadd local dirtrust   "Average"
		estadd local dirsample  "All dirs"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col7, add(nofirms r(ndistinct))
eststo col8: /// all directors
	reghdfe meandirtrust bitrust if ${sample} & tagbrdeubmceoyr, ///
	a(ceoid eubmcode boardid#year) cluster(${cluster}) keepsin
		estadd local sample     "All invs"
		estadd local dirtrust   "Average"
		estadd local dirsample  "All dirs"
		estadd local FE_IC      "X"
		estadd local FE_CEO     "X"
		estadd local FE_FxY     "X"
		distinct brdeubmcode if e(sample)
		estadd scalar nofirmxcntrys = r(ndistinct)
		distinct boardid if e(sample)
		eststo col8, add(nofirms r(ndistinct))

esttab /*using "Table A24_Bilateral trust and director selection.tex"*/, ///
	cells(b(star fmt(3)) se(par fmt(3))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	nomtitle collabels(none) label varwidth(27) modelwidth(12) ///
	mgroups("Director's bilateral trust", pattern(1 0 0 0 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
	keep(bitrust) coeflab(bitrust "CEO's bilateral trust") ///
	stats(sample dirtrust dirsample FE_F FE_Y FE_IC FE_CEO FE_FxY N nofirmxcntrys nofirms, ///
		fmt(%9.0fc %9.0fc %9.0fc) ///
		lab("Bilateral trust sample" "Director trust measure" "Director sample" ///
			"Firm FEs" "Year FEs" "Inventor country FEs" "CEO FEs" "Firm $\times$ Year FEs" ///
			"Observations" "Firm $\times$ Inv country's" "Firms"))

cap log close

********************************************************************************
*                 FIGURE A1: CEO'S TRUST AND FIRM'S INNOVATION                 *
********************************************************************************

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set sample
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
qui reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, a(boardid year) keepsin
keep if e(sample)
* demean by firm
foreach var in f1allpat f1allpatw ash_f1allpat trust trust_sd {
	bysort boardid: egen tempmean = mean(`var')
	gen res_`var' = `var' - tempmean 
	drop tempmean
}
* average by bin
gen bin = floor(res_trust * 270)
replace bin = bin + 1 if res_trust > 0
foreach var in f1allpat f1allpatw ash_f1allpat trust trust_sd {
	bysort bin: egen mres_`var' = mean(res_`var')
}


//PREPARE FIGURE
twoway ///
	(lfitci res_ash_f1allpat res_trust) ///
	(lfit res_ash_f1allpat res_trust, lpattern(solid) lcolor(cranberry) lwidth(medium)) ///
	(scatter mres_ash_f1all mres_trust, msymbol(circle) mcolor(navy) msize(medsmall)) ///
	if inrange(bin, -20, 18), ///
		xtitle("CEO's trust", size(medsmall)) ///
		xlabel(-0.075(0.025)0.075, labsize(medsmall) nogrid) ///
		ytitle("arsinh(Firm's patents)", size(medsmall)) ///
		ylabel(-0.15(0.05)0.15, labsize(medsmall) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A1_CEO trust and firm patents.gph", replace
graph export "Fig A1_CEO trust and firm patents.png", as(png) replace
graph export "Fig A1_CEO trust and firm patents.tif", as(tif) replace


********************************************************************************
*       FIGURE A2: PRE-CHANGE FIRM PERFORMANCE AND CHANGE IN CEO'S TRUST       *
********************************************************************************

//PREPATE DATA
use "CEO transition event sample.dta", clear
* construct additional variables
gen yrbfchange_agg = min(abs(yrbfchange), 7)
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global preeventsample = "!bothnonUS & yrbfchange != 0"
global cluster = "boardid"


//PREPARE FIGURE
* FIGURE A2A: Common trends in R&D expenditure
reghdfe deltatrust c.ash_xrd#i.yrbfchange_agg trustbf logat ${firm} ${ceo} ///
	if ${preeventsample} & yrbfchange != 0, a(sic3#yrbfchange_agg year) cluster(${cluster})

foreach var in yr beta lower upper {
	cap drop `var'
	gen `var' = .
}
replace yr = _n
forval i = 1/7 {
	replace beta = _b[`i'.yrbfchange_agg#ash_xrd] if yr == `i'
	replace lower = _r_lb[`i'.yrbfchange_agg#ash_xrd] if yr == `i'
	replace upper = _r_ub[`i'.yrbfchange_agg#ash_xrd] if yr == `i'
}
replace yr = -yr

twoway ///
	(rcap lower upper yr, lcolor(gray) lwidth(medium)) ///
	(scatter beta yr, msymbol(circle) mcolor(navy) msize(medlarge)) ///
	if inrange(yr, -6, -1), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medium)) ///
		xtitle("Year relative to CEO transition", size(medium)) ///
		xlabel(-6(1)-1, labsize(medium) nogrid) ///
		ytitle("Effect of arsinh(R&D exp.) on change in CEO's trust", size(medium)) ///
		ylabel(-0.06(0.02)0.06, labsize(medium) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A2A_Common trends in RnD expenditure.gph", replace
graph export "Fig A2A_Common trends in RnD expenditure.png", as(png) replace
graph export "Fig A2A_Common trends in RnD expenditure.tif", as(tif) replace


* FIGURE A2B: Common trends in employment
reghdfe deltatrust c.logemp#i.yrbfchange_agg trustbf ${firm} ${ceo} ///
	if ${preeventsample} & yrbfchange != 0, a(sic3#yrbfchange_agg year) cluster(${cluster})

foreach var in yr beta lower upper {
	cap drop `var'
	gen `var' = .
}
replace yr = _n
forval i = 1/7 {
	replace beta = _b[`i'.yrbfchange_agg#logemp] if yr == `i'
	replace lower = _r_lb[`i'.yrbfchange_agg#logemp] if yr == `i'
	replace upper = _r_ub[`i'.yrbfchange_agg#logemp] if yr == `i'
}
replace yr = -yr

twoway ///
	(rcap lower upper yr, lcolor(gray) lwidth(medium)) ///
	(scatter beta yr, msymbol(circle) mcolor(navy) msize(medlarge)) ///
	if inrange(yr, -6, -1), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medium)) ///
		xtitle("Year relative to CEO transition", size(medium)) ///
		xlabel(-6(1)-1, labsize(medium) nogrid) ///
		ytitle("Effect of ln(employment) on change in CEO's trust", size(medium)) ///
		ylabel(-0.06(0.02)0.06, labsize(medium) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))	
graph save "Fig A2B_Common trends in employment.gph", replace
graph export "Fig A2B_Common trends in employment.png", as(png) replace
graph export "Fig A2B_Common trends in employment.tif", as(tif) replace


* FIGURE A2C: Common trends in sales
reghdfe deltatrust c.logsale#i.yrbfchange_agg trustbf ${firm} ${ceo} ///
	if ${preeventsample} & yrbfchange != 0, a(sic3#yrbfchange_agg year) cluster(${cluster})	

foreach var in yr beta lower upper {
	cap drop `var'
	gen `var' = .
}
replace yr = _n
forval i = 1/7 {
	replace beta = _b[`i'.yrbfchange_agg#logsale] if yr == `i'
	replace lower = _r_lb[`i'.yrbfchange_agg#logsale] if yr == `i'
	replace upper = _r_ub[`i'.yrbfchange_agg#logsale] if yr == `i'
}
replace yr = -yr

twoway ///
	(rcap lower upper yr, lcolor(gray) lwidth(medium)) ///
	(scatter beta yr, msymbol(circle) mcolor(navy) msize(medlarge)) ///
	if inrange(yr, -6, -1), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medium)) ///
		xtitle("Year relative to CEO transition", size(medium)) ///
		xlabel(-6(1)-1, labsize(medium) nogrid) ///
		ytitle("Effect of ln(sales) on change in CEO's trust", size(medium)) ///
		ylabel(-0.06(0.02)0.06, labsize(medium) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A2C_Common trends in sales.gph", replace
graph export "Fig A2C_Common trends in sales.png", as(png) replace
graph export "Fig A2C_Common trends in sales.tif", as(tif) replace


* FIGURE A2D: Common trends in total assets
reghdfe deltatrust c.logat#i.yrbfchange_agg trustbf ${firm} ${ceo} ///
	if ${preeventsample} & yrbfchange != 0, a(sic3#yrbfchange_agg year) cluster(${cluster})	

foreach var in yr beta lower upper {
	cap drop `var'
	gen `var' = .
}
replace yr = _n
forval i = 1/7 {
	replace beta = _b[`i'.yrbfchange_agg#logat] if yr == `i'
	replace lower = _r_lb[`i'.yrbfchange_agg#logat] if yr == `i'
	replace upper = _r_ub[`i'.yrbfchange_agg#logat] if yr == `i'
}
replace yr = -yr

twoway ///
	(rcap lower upper yr, lcolor(gray) lwidth(medium)) ///
	(scatter beta yr, msymbol(circle) mcolor(navy) msize(medlarge)) ///
	if inrange(yr, -6, -1), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medium)) ///
		xtitle("Year relative to CEO transition", size(medium)) ///
		xlabel(-6(1)-1, labsize(medium) nogrid) ///
		ytitle("Effect of ln(total assets) on change in CEO's trust", size(medium)) ///
		ylabel(-0.06(0.02)0.06, labsize(medium) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A2D_Common trends in total assets.gph", replace
graph export "Fig A2D_Common trends in total assets.png", as(png) replace
graph export "Fig A2D_Common trends in total assets.tif", as(tif) replace


********************************************************************************
*            FIGURE A3: CEO'S TRUST EFFECT BY CHANGE IN CEO'S TRUST            *
********************************************************************************

//PREPARE DATA
use "CEO transition event sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global eventsample = "!bothnonUS"
global cluster = "mainethcode"


//PREPARE FIGURE
global N = 100
global band = 0.2
cap drop Xvar
gen Xvar = deltatrust if ${eventsample}
sum Xvar
global min = r(min)
global max = r(max)
global range = ${max} - ${min}
global bandwidth = ${band} * ${range}

cap drop beta se lower upper
foreach var in beta se lower upper {
	gen `var' = .
}
gen n = _n - 1
forval i = 0/$N {
	quietly {
		local point = ${min} + `i' * ${range}/${N}
		gen weight = normalden((Xvar - `point')/${bandwidth})
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
			[aw = weight], a(eventid year) cluster(${cluster}) keepsin
		drop weight
	
		replace beta = _b[trust_sd] if n == `i'
		replace se = _se[trust_sd] if n == `i'
		replace lower = _r_lb[trust_sd] if n == `i'
		replace upper = _r_ub[trust_sd] if n == `i'
	}
}
replace n = ${min} + n * ${range}/${N}

twoway ///
	(line beta n, lcolor(navy) lpattern(solid) lwidth(medium)) ///
	(line lower n, lcolor(gray) lpattern(shortdash) lwidth(thin)) ///
	(line upper n, lcolor(gray) lpattern(shortdash) lwidth(thin)) ///
	if inrange(n, floor(${min}), floor(${max}+1)), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medthin)) ///
		xtitle("Change in CEO's trust (z-score)", size(medsmall)) ///
		xlabel(-3(1)3, labsize(medsmall) nogrid) ///
		ytitle("Effect of CEO's trust on arsinh(patents)", size(medsmall)) ///
		ylabel(0(0.05)0.15, labsize(medsmall) nogrid) ///		
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A3_Effect by change in CEO trust.gph", replace
graph export "Fig A3_Effect by change in CEO trust.png", as(png) replace
graph export "Fig A3_Effect by change in CEO trust.tif", as(tif) replace


********************************************************************************
*         FIGURE A4: DISTRIBUTION OF BOOTSTRAPPED CEO'S TRUST EFFECTS          *
********************************************************************************

//PREPARE DATA	
use "Baseline CEO firm year sample.dta", clear	
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"
* estimate bootstrapped CEO's trust effects
gen round = _n
gen beta = .
gen se = .
forval i = 1/1000 {
	dis "BOOTSTRAPPING ROUND `i'"
	quietly {
		drop trust*
		merge m:1 ceoid using "ROUND `i' bootstrapped trust by CEO.dta"
		drop if _m == 2
		drop _m
	
		cap reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, ///
			a(boardid year) cluster(${cluster}) keepsin
		replace beta = _b[trust_sd] if round == `i'
		replace se = _se[trust_sd] if round == `i'
	}
}
keep round beta se
keep if beta != .
save "DATA bootstrapped trust estimates.dta", replace


//PREPARE FIGURE
use "Baseline CEO firm year sample.dta", clear	
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample}, a(boardid year) keepsin
global beta_actual = round(_b[trust_sd] * 1000)/1000

use "DATA bootstrapped trust estimates.dta", clear
sum beta
global beta_mean = round(r(mean) * 1000)/1000
global beta_corrected = ${beta_actual} + (${beta_actual} - ${beta_mean}) 

kdensity beta, title("") note("") lcolor(navy) lpattern(solid) lwidth(medium) ///
	xline(${beta_mean}, lpattern(solid) lcolor(cranberry) lwidth(medthin)) ///
	text(0 ${beta_mean} "Bootstrapped mean = 0${beta_mean}", ///
		place(nw) orientation(vertical) size(small) color(cranberry)) ///
	xline(${beta_actual}, lpattern(solid) lcolor(cranberry) lwidth(medthin)) /// 
	text(0 ${beta_actual} "Actual coefficient = 0${beta_actual}", ///
		place(nw) orientation(vertical) size(small) color(cranberry)) ///
	xline(${beta_corrected}, lpattern(solid) lcolor(cranberry) lwidth(medthin)) /// 
	text(0 ${beta_corrected} "Bias-corrected estimate = 0${beta_corrected}", ///
		place(nw) orientation(vertical) size(small) color(cranberry)) ///
	xtitle("Effect of bootstrapped CEO's trust on arsinh(patents)", size(medsmall)) ///
	xlabel(0.01(0.01)0.09, labsize(medsmall) nogrid) ///
	ytitle("Density", size(medsmall)) ///
	ylabel(0(10)40, labsize(medsmall) nogrid) ///
	graphregion(color(white) lwidth(vvvthick))
graph save "Fig A4_Bootstrapped effects.gph", replace
graph export "Fig A4_Bootstrapped effects.png", as(png) replace
graph export "Fig A4_Bootstrapped effects.tif", as(tif) replace


********************************************************************************
*        FIGURE A5: CEO'S TRUST EFFECTS WITHOUT INFLUENTIAL ETHNICITIES        *
********************************************************************************

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"
* define labels
label define groupeth 0 "None", replace
gen groupeth = 1 if mainethcode == 14 
label define groupeth 1 "Ireland", add
replace groupeth = 2 if mainethcode == 11
label define groupeth 2 "Germany", add
replace groupeth = 3 if mainethcode == 8
label define groupeth 3 "England & Wales", add
replace groupeth = 4 if inlist(mainethcode, 3, 4, 150)
label define groupeth 4 "Canada", add
replace groupeth = 5 if mainethcode == 24
label define groupeth 5 "Russia & USSR", add
replace groupeth = 6 if mainethcode == 15
label define groupeth 6 "Italy", add
replace groupeth = 7 if mainethcode == 24
label define groupeth 7 "Scotland", add
replace groupeth = 8 if mainethcode == 26
label define groupeth 8 "Sweden", add
replace groupeth = 9 if mainethcode == 21
label define groupeth 9 "Poland", add
replace groupeth = 10 if mainethcode == 2
label define groupeth 10 "Austria", add
replace groupeth = 11 if mainethcode == 19
label define groupeth 11 "Norway", add
replace groupeth = 12 if mainethcode == 5
label define groupeth 12 "China", add
replace groupeth = 13 if mainethcode == 17
label define groupeth 13 "Mexico", add
replace groupeth = 14 if mainethcode == 31
label define groupeth 14 "India", add
replace groupeth = 15 if mainethcode == 18
label define groupeth 15 "Netherlands", add
replace groupeth = 16 if mainethcode == 7
label define groupeth 16 "Denmark", add
replace groupeth = 17 if mainethcode == 6
label define groupeth 17 "Czechoslovakia", add
replace groupeth = 18 if mainethcode == 13
label define groupeth 18 "Hungary", add


//PREPARE FIGURE
cap drop beta se lower upper n
foreach var in beta se lower upper {
	gen `var' = .
}
gen n = _n - 1
forval i = 0/18 {
	quietly {
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${sample} & groupeth != `i', ///
			a(boardid year) cluster(${cluster}) keepsin
		replace beta = _b[trust_sd] if n == `i'
		replace se = _se[trust_sd] if n == `i'
		replace lower = _r_lb[trust_sd] if n == `i'
		replace upper = _r_ub[trust_sd] if n == `i'
	}
}
cap drop beta_base
gen beta_base = beta if n == 0
sum beta_base
global beta_base = r(mean)
label values n groupeth
twoway ///
	(rcap lower upper n, lcolor(gray) lwidth(thin)) ///
	(scatter beta n, msymbol(circle) mcolor(navy) msize(medsmall)) ///
	(scatter beta_base n, msymbol(circle) mcolor(cranberry) msize(medsmall)) ///
	if inrange(n, 0, 18), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medthin)) ///
		yline(${beta_base}, lpattern(shortdash) lcolor(cranberry) lwidth(medthin)) ///
		xtitle("CEO's ethnicity excluded from sample", size(small)) ///
		xlabel(0(1)18, labsize(small) value angle(vertical) nogrid) ///
		ytitle("Effect of CEO's trust on arsinh(patents)", size(small)) ///
		ylabel(-0.02(0.02)0.12, labsize(small) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A5_Excluding influential ethnicities.gph", replace
graph export "Fig A5_Excluding influential ethnicities.png", as(png) replace
graph export "Fig A5_Excluding influential ethnicities.tif", as(tif) replace


********************************************************************************
*           FIGURE A6: DIRECT EFFECTS OF CEO'S OTHER CULTURAL TRAITS           *
********************************************************************************

//PREPARE DATA
use "Baseline CEO firm year sample.dta", clear
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global sample = "year < 2012 & !nonUS"
global cluster = "mainethcode"
* define variables 
label define varname 0 "Generalized trust", replace
label define varname 1 "High-income share", add
label define varname 2 "Occupation prestige", add
label define varname 3 "Avg. schooling yrs.", add
label define varname 4 "College grad. share", add
label define varname 5 "Confdc. in science", add
label define varname 6 "Confdc. in Congress", add
label define varname 7 "Confdc. in Fed. Govt.", add
label define varname 8 "Confdc. in Sup. Court", add
label define varname 9 "Protestant share", add
label define varname 10 "Work ethic", add
label define varname 11 "Risk preference", add
label define varname 12 "Patience", add
label define varname 13 "Pos. reciprocity", add
label define varname 14 "Neg. reciprocity", add
label define varname 15 "Altruism", add


//PREPARE FIGURE
cap drop beta se lower upper n
foreach var in beta se lower upper {
	gen `var' = .
}
gen n = _n - 1
global i = 0
foreach var in ///
	trust_sd highincome_sd prestg_sd educyrs_sd coldeg_sd consci_sd conleg_sd confed_sd conjud_sd ///
	protestant_sd getahead_sd risktakinggps_sd patiencegps_sd posrecipgps_sd negrecipgps_sd altruismgps_sd {
	quietly {
		reghdfe ash_f1allpat `var' ${firm} ${ceo} if ${sample}, ///
			a(boardid year) cluster(${cluster}) keepsin
		replace beta = _b[`var'] if n == ${i}
		replace se = _se[`var'] if n == ${i}
		replace lower = _r_lb[`var'] if n == ${i}
		replace upper = _r_ub[`var'] if n == ${i}
		global i = ${i} + 1
	}
}
cap drop beta_base
gen beta_base = beta if n == 0
sum beta_base
global beta_base = r(mean)
label values n varname
twoway ///
	(rcap lower upper n, lcolor(gray) lwidth(thin)) ///
	(scatter beta n, msymbol(circle) mcolor(navy) msize(medsmall)) ///
	(scatter beta_base n, msymbol(circle) mcolor(cranberry) msize(medsmall)) ///
	if inrange(n, 0, 15), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medthin)) ///
		yline(${beta_base}, lpattern(shortdash) lcolor(cranberry) lwidth(medthin)) ///
		xtitle("CEO's inherited cultural traits", size(small)) ///
		xlabel(0(1)15, labsize(small) value angle(vertical) nogrid) ///
		ytitle("Effect of CEO's cultural traits on arsinh(patents)", size(small)) ///
		ylabel(-0.06(0.02)0.1, labsize(small) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A6_Effects of other cultural traits.gph", replace
graph export "Fig A6_Effects of other cultural traits.png", as(png) replace
graph export "Fig A6_Effects of other cultural traits.tif", as(tif) replace


********************************************************************************
*   FIGURE A8: CEO'S TRUST EFFECT BY PRE-TRANSITION RESEARCHER POOL QUALITY    *
********************************************************************************

//PREPARE DATA
use "CEO transition event sample.dta", clear
* construct additional variables
gen ash_efficiency = asinh(f1allpat/xrd)
replace ash_efficiency = asinh(f1allpat) if xrd == 0
* set globals
global firm = "firmage firmage2 ash_xrd"
global ceo = "gender age age2 yrinco i.education"
global eventsample = "!bothnonUS"
global cluster = "mainethcode"


//PREPARE FIGURE
global N = 100
global band = 0.2
cap drop Xvar
gen Xvar = resqual if ${eventsample}
sum Xvar
global min = r(min)
global max = r(max)
global range = ${max} - ${min}
global bandwidth = ${band} * ${range}

* FIGURE A8A: Effect on patents
cap drop beta se lower upper n
foreach var in beta se lower upper {
	gen `var' = .
}
gen n = _n - 1
forval i = 0/$N {
	quietly {
		local point = ${min} + `i' * ${range}/${N}
		gen weight = normalden((Xvar - `point')/${bandwidth})
		reghdfe ash_f1allpat trust_sd ${firm} ${ceo} if ${eventsample} ///
			[aw = weight], a(eventid year) cluster(${cluster}) keepsin
		drop weight
	
		replace beta = _b[trust_sd] if n == `i'
		replace se = _se[trust_sd] if n == `i'
		replace lower = _r_lb[trust_sd] if n == `i'
		replace upper = _r_ub[trust_sd] if n == `i'
	}
}
replace n = ${min} + n * ${range}/${N}

twoway ///
	(line beta n, lcolor(navy) lpattern(solid) lwidth(medium)) ///
	(line lower n, lcolor(gray) lpattern(shortdash) lwidth(thin)) ///
	(line upper n, lcolor(gray) lpattern(shortdash) lwidth(thin)) ///
	if inrange(n, floor(${min}), floor(${max}+1)), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medthin)) ///
		xtitle("Proxy for pre-transition researcher pool quality", size(medium)) ///
		xlabel(-4(2)6, labsize(medium) nogrid) ///
		ytitle("Effect of CEO's trust on arsinh(patents)", size(medium)) ///
		ylabel(-0.05(0.05)0.35, labsize(medium) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A8A_Effect on patents by researcher quality.gph", replace
graph export "Fig A8A_Effect on patents by researcher quality.png", as(png) replace
graph export "Fig A8A_Effect on patents by researcher quality.tif", as(tif) replace
		

* FIGURE A8B: Effect on R&D efficiency
cap drop beta se lower upper n
foreach var in beta se lower upper {
	gen `var' = .
}
gen n = _n - 1
forval i = 0/$N {
	quietly {
		local point = ${min} + `i' * ${range}/${N}
		gen weight = normalden((Xvar - `point')/${bandwidth})
		reghdfe ash_efficiency trust_sd ${firm} ${ceo} if ${eventsample} ///
			[aw = weight], a(eventid year) cluster(${cluster}) keepsin
		drop weight
	
		replace beta = _b[trust_sd] if n == `i'
		replace se = _se[trust_sd] if n == `i'
		replace lower = _r_lb[trust_sd] if n == `i'
		replace upper = _r_ub[trust_sd] if n == `i'
	}
}
replace n = ${min} + n * ${range}/${N}

twoway ///
	(line beta n, lcolor(navy) lpattern(solid) lwidth(medium)) ///
	(line lower n, lcolor(gray) lpattern(shortdash) lwidth(thin)) ///
	(line upper n, lcolor(gray) lpattern(shortdash) lwidth(thin)) ///
	if inrange(n, floor(${min}), floor(${max}+1)), ///
		yline(0, lpattern(solid) lcolor(cranberry) lwidth(medthin)) ///
		xtitle("Proxy for pre-transition researcher pool quality", size(medium)) ///
		xlabel(-4(2)6, labsize(medium) nogrid) ///
		ytitle("Effect of CEO's trust on R&D efficiency", size(medium)) ///
		ylabel(-0.05(0.05)0.35, labsize(medium) nogrid) ///
		legend(off) graphregion(color(white) lwidth(vvvthick))
graph save "Fig A8B_Effect on RnD efficiency by researcher quality.gph", replace
graph export "Fig A8B_Effect on RnD efficiency by researcher quality.png", as(png) replace
graph export "Fig A8B_Effect on RnD efficiency by researcher quality.tif", as(tif) replace


********************************************************************************
*     FIGURE A9: DISTRIBUTION OF CEO'S BILATERAL TRUST TOWARDS RESEARCHERS     *
********************************************************************************

use "Bilateral trust sample_nonUS.dta", clear
* set sample
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global bitrustsample = "eubmcode != 33 & haspat & year < 2012 & !nonUS" //eubmcode 33 = US
qui reghdfe ash_f1allpatxc bitrust_sd logat logsale ${firm} ${ceo} if ${bitrustsample}, ///
	a(boardid eubmcode ceoid year) keepsin
keep if e(sample)
keep ceoid eubmcode bitrust
duplicates drop

sum bitrust, det
global bitrust_p10 = r(p10)
global bitrust_p50 = r(p50)
global bitrust_p90 = r(p90)

histogram bitrust, ///
	width(0.05) color(navy) fintensity(inten80) lcolor(white) /// 
	xline(${bitrust_p10}, lpattern(shortdash) lcolor(cranberry) lwidth(medthin)) ///
	xline(${bitrust_p50}, lpattern(solid) lcolor(cranberry) lwidth(medthin)) ///
	xline(${bitrust_p90}, lpattern(shortdash) lcolor(cranberry) lwidth(medthin)) ///
	xtitle("CEO's bilateral trust measure", size(medsmall)) ///
	xlabel(1.5(0.5)3.5, labsize(medsmall) nogrid) ///
	ytitle("Density", size(medsmall)) ///
	ylabel(0(0.5)2, labsize(medsmall) nogrid) ///
	graphregion(color(white) lwidth(vvvthick))
graph save "Fig A9_CEO bilateral trust distribution.gph", replace
graph export "Fig A9_CEO bilateral trust distribution.png", as(png) replace
graph export "Fig A9_CEO bilateral trust distribution.tif", as(tif) replace


********************************************************************************
*      FIGURE A10: PRE-CHANGE PATENTS AND CHANGE IN CEO'S BILATERAL TRUST      *
********************************************************************************

//PREPARE DATA
* set globals
global firm = "firmage firmage2"
global ceo = "gender age age2 yrinco i.education"
global preeventsample = "sample & eubmcode != 33 & haspat & yrbfchange != 0" //eubmcode 33 = US
global cluster = "boardid"


//PREPARE FIGURE
foreach subfigure in "A" "B" {
	* SUBFIGURE A: Non-US-based inventors
	if "`subfigure'" == "A" {
		use "Bilateral trust transition event sample_nonUS.dta", clear
		global sample = "Non US"
	}
	* SUBFIGURE B: All inventors 
	if "`subfigure'" == "B" {
		use "Bilateral trust transition event sample_all.dta", clear
		global sample = "All"
	}
	* construct additional variables
	gen yrbfchange_agg = min(abs(yrbfchange), 7)	
	* set sample
	bysort eventid: egen sample = max(bitrustsample)
	
	reghdfe bitrustaf c.ash_allpatxc#i.yrbfchange_agg bitrustbf ${firm} ${ceo} ///
		if ${preeventsample}, a(boardid#yrbfchange_agg eubmcode year) cluster($cluster)

	foreach var in yr beta lower upper {
		cap drop `var'
		gen `var' = .
	}	
	replace yr = _n
	forval i = 1/7 {
		replace beta = _b[`i'.yrbfchange_agg#ash_allpat] if yr == `i'
		replace lower = _r_lb[`i'.yrbfchange_agg#ash_allpat] if yr == `i'
		replace upper = _r_ub[`i'.yrbfchange_agg#ash_allpat] if yr == `i'
	}
	replace yr = -yr
		
	twoway ///
		(rcap lower upper yr, lcolor(gray) lwidth(medium)) ///
		(scatter beta yr, msymbol(circle) mcolor(navy) msize(medlarge)) ///
		if inrange(yr, -6, -1), ///
			yline(0, lpattern(solid) lcolor(cranberry) lwidth(medium)) ///
			xtitle("Year relative to CEO transition", size(medium)) ///
			xlabel(-6(1)-1, labsize(medium) nogrid) ///
			ytitle("Effect of arsinh(patents) on change in CEO's trust", size(medium)) ///
			ylabel(-0.2(0.1)0.2, labsize(medium) nogrid) ///
			legend(off) graphregion(color(white) lwidth(vvvthick))	
	graph save "Fig A10`subfigure'_Patent common trends_${sample} inventors.gph", replace
	graph export "Fig A10`subfigure'_Patent common trends_${sample} inventors.png", as(png) replace
	graph export "Fig A10`subfigure'_Patent common trends_${sample} inventors.tif", as(tif) replace
}

********************************************************************************
*  FIGURE A11: CEO'S BILATERAL TRUST EFFECTS WITHOUT INFLUENTIAL ETHNICITIES   *
********************************************************************************

//PREPARE DATA
* set globals
global firm = "firmage firmage2"
global ceo = "age age2 yrinco"
global bitrustFEs = "ceoid eubmcode boardid#year"
global bitrustsample = "eubmcode != 33 & haspat & year < 2012 & !nonUS" //eubmcode 33 = US
global cluster = "etheubmcode"


//PREPARE FIGURE
foreach subfigure in "A" "B" {
	* SUBFIGURE A: Non-US-based inventors
	if "`subfigure'" == "A" {
		use "Bilateral trust sample_nonUS.dta", clear
		global sample = "Non US"
	}
	* SUBFIGURE B: All inventors 
	if "`subfigure'" == "B" {
		use "Bilateral trust sample_all.dta", clear
		global sample = "All"
	}
	* set sample
	qui reghdfe ash_f1allpatxc bitrust_sd logat logsale ${firm} ${ceo} if ${bitrustsample}, ///
		a(boardid eubmcode ceoid year) keepsin
	gen bitrustsample = e(sample)
	* define labels
	label define groupeth 0 "None", replace
	gen groupeth = 1 if mainethcode == 8 
	label define groupeth 1 "Ireland", add
	replace groupeth = 2 if mainethcode == 4
	label define groupeth 2 "Germany", add
	replace groupeth = 3 if mainethcode == 9
	label define groupeth 3 "Great Britain", add
	replace groupeth = 4 if mainethcode == 5
	label define groupeth 4 "Italy", add
	replace groupeth = 5 if mainethcode == 17
	label define groupeth 5 "Sweden", add
	replace groupeth = 6 if mainethcode == 15
	label define groupeth 6 "Norway", add
	replace groupeth = 7 if mainethcode == 7
	label define groupeth 7 "Denmark", add
	replace groupeth = 8 if mainethcode == 3
	label define groupeth 8 "Netherlands", add
	replace groupeth = 9 if mainethcode == 12
	label define groupeth 9 "Spain", add
	replace groupeth = 10 if mainethcode == 1
	label define groupeth 10 "France", add
	replace groupeth = 11 if mainethcode == 11
	label define groupeth 11 "Greece", add
	replace groupeth = 12 if mainethcode == 13
	label define groupeth 12 "Portugal", add
	replace groupeth = 13 if mainethcode == 16
	label define groupeth 13 "Finland", add
	
	cap drop beta se lower upper n
	foreach var in beta se lower upper {
		gen `var' = .
	}
	gen n = _n - 1
	forval i = 0/13 {
		quietly {	
			reghdfe ash_f1allpatxc bitrust_sd if bitrustsample & groupeth != `i', ///
				a(${bitrustFEs}) cluster(${cluster}) keepsin
			replace beta = _b[bitrust_sd] if n == `i'
			replace se = _se[bitrust_sd] if n == `i'	
			replace lower = _r_lb[bitrust_sd] if n == `i'
			replace upper = _r_ub[bitrust_sd] if n == `i'		
		}
	}
	cap drop beta_base
	gen beta_base = beta if n == 0
	sum beta_base
	global beta_base = r(mean)
	label values n groupeth
	twoway ///
		(rcap lower upper n, lcolor(gray) lwidth(medium)) ///
		(scatter beta n, msymbol(circle) mcolor(navy) msize(medlarge)) ///
		(scatter beta_base n, msymbol(circle) mcolor(cranberry) msize(medlarge)) ///
		if inrange(n, 0, 12), ///
			yline(0, lpattern(solid) lcolor(cranberry) lwidth(medium)) ///
			yline(${beta_base}, lpattern(shortdash) lcolor(cranberry) lwidth(medium)) ///
			xtitle("Ethnicity excluded from sample", size(medium)) ///
			xlabel(0(1)12, labsize(medium) value angle(vertical) nogrid) ///
			ytitle("Effect of CEO's trust on arsinh(patents)", size(medium)) ///
			ylabel(-0.02(0.02)0.12, labsize(medium) nogrid) ///		
			legend(off) graphregion(color(white) lwidth(vvvthick))
	graph save "Fig A11`subfigure'_Excluding influential ethnicities_${sample} inventors.gph", replace
	graph export "Fig A11`subfigure'_Excluding influential ethnicities_${sample} inventors.png", as(png) replace
	graph export "Fig A11`subfigure'_Excluding influential ethnicities_${sample} inventors.tif", as(tif) replace
}